Click to See Complete Forum and Search --> : Help needed for IN keyword


arcware
10-31-2007, 03:29 AM
Hi,
I have 2 tables, tbl_cards (id, cardname) and tbl_crdservices (cardId,serviceId).
I need to fetch data from tbl_card where the cardname should have services in tbl_cardservice. For ex. select all cards which provide serviceId 5 and 6. I can use IN keyword Like Select c.* from tbl_cards c INNER JOIN tbl_cardServices cs ON c.Id = cs.CardId and cs.ServiceID IN (5,6)
but... IN keyword gives result on OR basis, means cards having id 5 or 6 will be returned, and I need result where the card having both services should return.

Please help.

Thanks

NogDog
10-31-2007, 04:45 AM
How about:

SELECT c.* FROM tbl_cards c
INNER JOIN tbl_cardServices cs1 ON c.Id = cs1.CardId
INNER JOIN tbl_cardServices cs2 ON c.Id = cs2.CardId
WHERE cs1.ServiceID = 5 AND cs2.ServiceID = 6

I have a hunch there's a simpler way, but this is all that's coming to mind right now.