SQLTeam.com | Weblogs | Forums

Select Records that Have 2 values for a Fields


#1

Hi
My table
Create table Table1 (GoodsId int,LocNumber int)
Insert into Table1(GoodsId,LocNumber)
Values (1,500)
,(1,501)
,(1,502)
,(2,501)
,(2,502)
,(3,500)
,(3,502)
,(4,500)
,(4,501)
,(4,502)

I Search for Which goodsId that Have 500 And 501 For LocNumbers .
Then The rsult Should be : 1 , 4
Please help me to Write Query
Thank you


#2
select     GoodsId
from       #Table1
where      LocNumber    in (500, 501)
group by   GoodsId
having     min(LocNumber)    <> max(LocNumber)