EmpId FirstName LastName
1 Bob Lync
2 Sarah John
3 Bob Lync
4 John Doe
5 Stanly Jeff
6 Sarah John
With a single SQL query, how will you cleanup the database (eliminate redundant data from above table)
Solution: using group by, and we can find the first appearance of the empid of each user.
DELETE FROM emp
WHERE empid NOT IN
(SELECT MIN(empid)
FROM emp
GROUP BY firstName , lastName);
没有评论:
发表评论