My first table is as below (not important):
tbl_Item
ItemId,ItemName
1 ,'test'
2 ,'test2'
3 , 'test3'
and second table is (Important table),this table tell us that ItemId has what specifications? For example ItemId 1 has specs 5 and 6 and 7
tbl_Spec
ItemId , SpecId
1 ,5
1 ,6
1 ,7
2 ,5
2 ,8
3 ,5
3 ,7
How can I select Items that have both SpecId 5 and 7
the result must be :
ItemId
1
3
SQL In (…) do the OR as default, but I want something with And Function.
My DBMS is SQL Server 2008
I’m sure there must be more elegant ways, but this should give you what you want (EDIT: fixed as per Michaeł Powaga’s suggestion).
p.s. Ali , if you need a more easily expandable solution, have you seen Mikael Eriksson’s answer?