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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 few queries

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 null

2) 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.region
group by c.region

select c.region,count(s.supplierid) from suppliers s join products p on s.supplierid=p.supplierid
join orderdetails od on p.productid=od.productid join orders o on o.orderid=od.orderid join customers c on o.customerid=c.customerid
where s.region=c.region
group by c.region

Again 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 one
1.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.productid
where productidis null

3.select productname from products p where not exists(select * from orderdetails where productid = p.productid )
Go to Top of Page
   

- Advertisement -