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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 select statement help

Author  Topic 

helixpoint
Constraint Violating Yak Guru

291 Posts

Posted - 2012-05-05 : 12:11:33
I have 2 tables. I only want to bring back sellers who have product available. Sally has none

1st table seller
sellerID Seller Name
1 Bob
2 Jim
3 sally
2nd table product
sellerID isSold(bit)
1 0
1 0
1 1
2 0
2 0

Dave
Helixpoint Web Development
http://www.helixpoint.com

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-05 : 12:31:11
[code]
select s.SellerName
from seller s
inner join product p
on p.sellerID = s.sellerID
group by s.SellerName
having sum(case when isSold=0 then 1 else 0 end) >0
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -