Link to home
Start Free TrialLog in
Avatar of mnoisette
mnoisetteFlag for United States of America

asked on

SQL SUBQUERY

Using the Northwind Database, write a sub-query to find all products that have never been ordered.
Show the product Id and the product name in your results.
Avatar of Brendt Hess
Brendt Hess
Flag of United States of America image

Heh. Homework.

Hint: use LEFT JOIN.
You don't need sub-query, just a query where there are two tables Products and Order Details. So, with left join Order Details table will have null value (Where o.ProductID is null).

Also, you need to use Distinct keyword to eliminate repeats. But, if you have to use sub-query for some reason, try "2. Correlated subqueries".

Mike
ASKER CERTIFIED SOLUTION
Avatar of Jeff Darling
Jeff Darling
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mnoisette

ASKER

This is a trick question and I do know that I could have written the query using an Outer Join, but they wanted it done with a subquery.
Jeff has the solution for you. If you want more explanation on the five types of subqueries, see the link I have included in my last post. I also found out all products has been ordered in my version of northwind database.

Mike
Thanks dude!