Adobe Interview Question Software Engineer in Tests
0of 0 votesYou have a database table Emp with data as follows:
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)
Country: United States
delete from Emp where Emp.EmpId IN (select EmpId from Emp Emp2 where Emp.FirstName = Emp2.FirstName and Emp.LastName = Emp2.LastName and Emp2.EmpId <> Emp.EmpId)
Won't this delete every instance of duplicated data?
Perhaps we should do Emp2.EmpId > Emp.EmpId, rather than <>.
Select emp id, first name, last name, count (*) from EMP
Group by first name, last name
where count(*) > 1
this will return the duplicate records and Delete it using delete query....
This code works fine for me. have used Common Table expressions .
WITH CTE_1
AS (
SELECT first_name, last_name, ROW_NUMBER() OVER (ORDER BY first_name,last_name) AS keep_ID ,
DENSE_RANK() OVER(ORDER BY first_name,last_name) AS RANK FROM persons_cup)
DELETE FROM CTE_1 WHERE keep_ID NOT IN
(SELECT MIN(keep_id) FROM CTE_1 B GROUP BY RANK)

delete from employee where rowid not in (select min(rowid) from employee group by firstName , lastName)
- entityvsentityv2 on August 02, 2012 Edit | Flag Reply