Facebook Interview Question for Software Engineer / Developers






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

select email, count(email)
from table
group by email
having count(email) > 1

- gallant March 01, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This query is the correct one

- DEEPAK GURUNG October 16, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

gallant nailed it!

- vic December 23, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

select distinct email
from table

- superficial March 31, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

it doesn't work if there is email exists more than twice.

- Anonymous September 08, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

select *
from email_table
group by email
having count(*) > 1

- Anonymous November 20, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

lol ..

- Anonymous May 14, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

select email from email_table
where email NOT IN
(select email from email_table where count(email) = 1)

- Johnny February 04, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Perfect!! But one change
select distinct email from email_table
where email NOT IN
(select email from email_table where count(email) = 1)

This is because we don't need same e-mail id repeating several times in output

- Bravo July 03, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

The "having count" solution works fine.

Here is another one:

select 
	ec.email 
from 
	(select 
		e.email, 
		count(e.mail) as email_count 
	from 
		email as e 
	group by e.email) as ec 
where 
	ec.email_cout > 1

- Jin October 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

select email_id from email_table where count(email_id)>1;

- Sunil October 26, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Not even a valid SQL query - can't use the aggregate function count with where. If you just change where to having, that'll give you only one result. You need a group by clause which makes it the same as the very first answer.

- Anonymous November 07, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

SELECT ROWID , EMAIL_ADDRESS FROM EMAIL_TABLE
WHERE ROWID NOT IN (SELECT MAX(ROWID) FROM EMAIL_TABLE GROUP BY EMAIL_ADDRESS)

- Sum November 28, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

select t1.email from
t as T1, t as T2
where T1.email == T2.email

- Anonymous September 09, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

SELECT EMAIL,COUNT(EMAIL)
FROM TABLE
GROUP BY EMAIL
HAVING COUNT(EMAIL)>1

- Anonymous April 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If the table has only one column and this is a relational database, we cannot have duplicates in the table!

- Anonymous October 10, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Could be solved with self join:
select distinct(a.email) from emails a join emails b on a.email=b.email and a.id!=b.id;

- Acarus November 22, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

with dups_tbl as
(
select email,row_number() over(order by email) rn
from table
)
select distinct email from dups_tbl where rn > 1;

- Sasikumar Ravichandran May 22, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

select distinct email
from table

- superficial March 31, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

this won't work as you are getting all emails address, not just the one that are duplicates

- tejas June 10, 2009 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

select email 
from table
where email NOT IN (select distinct email from table)

- bokay July 23, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 votes

This will always return 0 row, but the following might work

select email from email_table
MINUS
select distinct email from email_table

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

Whats wrong with first one?
Most elegant and efficient, all interviewer is trying to judge your knowledge of Group By and Having clause.

- pk August 24, 2009 | 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