Adobe Interview Question for Software Engineer in Tests


Country: United States




Comment hidden because of low score. Click to expand.
13
of 13 vote

delete from employee where rowid not in (select min(rowid) from employee group by firstName , lastName)

- entityvsentityv2 August 02, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

it will delete all duplicated instance..

- nikhilranjan234 August 14, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Query is fine.. Nikhil... Hw can it deletes all duplicates ??

- dildileepkumar October 06, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

absolutely correct query cause for each insert there would be unique index generated no mattr insertion is repeated or not. In answer d query is deleting the duplicate indices using Not in.

- swapnil January 06, 2013 | Flag
Comment hidden because of low score. Click to expand.
3
of 3 vote

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)

- Elijah July 31, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Won't this delete every instance of duplicated data?

Perhaps we should do Emp2.EmpId > Emp.EmpId, rather than <>.

- Anonymous August 01, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yeh this will delete all duplicate values

- Hoper October 11, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

ALTER IGNORE TABLE emp ADD UNIQUE INDEX(first,last)

- woggle August 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

delete from employee where employeeId in 
(
select top 2 employeeid from employee where 
employeename in (select employeeName from employee group by employeeName having count(*) > 1) order by employeeId desc)

- Niraj November 30, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

use CTE

- ayangyang June 02, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

You could use Rank() function to identify the duplicate row

Select Rank() over(Partition by firstname, lastname order by rowid) rank_n, RowId, FirstName, LastName from Employee

The above function will give you the ranking based on the firstname and lastname combination.

delete the records for the identified rowId's from above query where rank_n >1

- Raj July 09, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

with CTE as
(select *,row_number() over(partition by FirstName,LastName order by firstname) as RR
from ee1)
delete from CTE where RR>1

- Sushil September 02, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

del from emp
where id not in (sel min(id) from emp group by fname, lname having count(*)>=1)

- Shruti September 05, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

;with cte as
(
select *, row_number() over (partition by name order by name desc) as dup_name from name)
delete from cte where dup_name>1

- Ayushi June 15, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I am assuming you aren't allowed to use nested queries either. Hence.

DROP TABLE IF EXISTS `person`;

CREATE TABLE `person` (
  `emp_id` int(11) NOT NULL auto_increment,
  `first_name` varchar(64) NOT NULL,
  `last_name` varchar(64) NOT NULL,
  PRIMARY KEY  (`emp_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

insert into person (first_name, last_name) values ('bob', 'lync');
insert into person (first_name, last_name) values ('sarah', 'john');
insert into person (first_name, last_name) values ('bob', 'lync');
insert into person (first_name, last_name) values ('john', 'doe');
insert into person (first_name, last_name) values ('stanly', 'jeff');
insert into person (first_name, last_name) values ('sarah', 'john');

select a.* from person a, person b
where a.first_name = b.first_name
and a.last_name = b.last_name
and a.emp_id > b.emp_id;

delete a.*
from person a, person b
where a.first_name = b.first_name
and a.last_name = b.last_name
and a.emp_id > b.emp_id;

- rohithv April 28, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

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....

- Gyanendra prasad Giri September 02, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This query wont work - the group by clause wont let you have the emp id in the select clause, as you are aggregating on first and last names.

- Makarand May 30, 2013 | Flag
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
1
of 1 vote

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)

- Nilesh.K.Molankar October 15, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

This one works !!

- Vishal December 31, 2012 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More