Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SELECT Query - AND on 2 rows? 1

Status
Not open for further replies.

wendyp

IS-IT--Management
Mar 4, 2003
51
US
I have a table like this:

Code:
id     cat_id
1        3
2        3
3        3
1        4
2        5
So an ID can have more than one category. I want to select records that are in both category 3 and 4.

If I make an SQL statement with OR, I'll get all the items for category 3 and category 4. But if I do an and, I'll get no records.

Do I need to make a temporary table with:
Code:
id     cats
1       3,4
2       3,5
3       3

Or do I run 2 queries, 1 for the first category and 1 for the second category and then find the duplicates?

What is the best way to do this?

Thanks,
/Wendy
 
Beautiful! Thanks a million - I would have never thought of that. And I knew it had to be simple.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top