Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
smile
Starting Member
22 Posts |
Posted - 2009-04-05 : 18:46:08
|
| Hello!I was using the Northwind database and I don't get few queries:1)Retrieve the names of the products that were never ordered.Which of the two queries is the right one? I suppose that it's the first?select productname from products where productid not in (select productid from orderdetails)select productname from products p left join orderdetails od on p.productid=od.productid--where orderid is null2) Retrieve the number of the suppliers that have the same region like the client.select c.region,count(supplierid) from suppliers s join customers c on s.region=c.regiongroup by c.regionselect c.region,count(s.supplierid) from suppliers s join products p on s.supplierid=p.supplieridjoin orderdetails od on p.productid=od.productid join orders o on o.orderid=od.orderid join customers c on o.customerid=c.customeridwhere s.region=c.regiongroup by c.regionAgain I suppose that the first one is the right one?Thanks a lot! |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-04-06 : 00:49:47
|
| in first case u can use any one of it prefer 2 one1.select productname from products where productid not in (select productid from orderdetails)2.select productname from products p left join orderdetails od on p.productid=od.productidwhere productidis null3.select productname from products p where not exists(select * from orderdetails where productid = p.productid ) |
 |
|
|
|
|
|