Interview Question for Software Engineer in Tests


Country: United States
Interview Type: Phone Interview




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

Write a query that returns the list of DVDs that belong to owners who own “Superman”

--> the list of DVDs should be distinct, and you only want the DVD Titles (At least when I was teaching assistance for a DB class, I make my student not to output useless stuff).

This line only give you SUPERMAN and nothing else. It is wrong. All, the where clause is wrong-.-

You should do subquery. first get the people with SUPERMAN, kindof like your query:

SELECT Owner_ID
FROM DVD d
WHERE Title = 'Superman' ;

Then join them back and get all DVD title

SELECT DISTINCT Title
FROM DVD d,Person p INNERJOIN Person p ON p.Person_id = d.Owner_ID
WHERE p.Person_ID IN 
(SELECT Owner_ID
FROM DVD d
WHERE Title = 'Superman') ;

- Mo Lam May 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 votes

Also, fix the cases in my SQL.

If you do not use subquery, you will need a 3 table join (DVD a <--> Person <--> DVD b). both on OWNER_ID = PERSON_ID, where a.Title = 'superman' and select DISTINCT b.Title

SELECT DISTINCT b.Title
FROM (DVD a,Person p INNER JOIN Person p ON p.Person_id = a.Owner_ID) INNER JOIN DVD b ON p.PersonID = b.Owner_ID
WHERE a.Title = "Superman"

- Mo Lam May 16, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

First solution (subquery) should be faster since the where happened eariler.

- Mo Lam May 16, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I third 3rd line should be 'WHERE p.person_id = d.Owner_id

- Anonymous May 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

SELECT TITLE FROM DVD WHERE OWNER_ID IN
(SELECT PERSON_ID FROM PERSON WHERE NAME = 'SUPERMAN')

- rizwan.amd May 17, 2013 | Flag Reply


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