Welcome to WebmasterWorld Guest from 35.175.191.168

Forum Moderators: open

Message Too Old, No Replies

Query help needed (on MySQL 4.1.2)

     
10:44 am on Jul 21, 2008 (gmt 0)

Junior Member

10+ Year Member

joined:Mar 17, 2005
posts: 109
votes: 0


Sorry for the rubbish post title...

I have two columns, say 'widget_id' & 'category_id'.

select widget_id from tbl where category_id=9 gives me a list of widget_ids 1,2,3..100

My question - is there another way to find the answer to the following query without using a monster 'IN':

select distinct(category_id) from tbl where widget_id IN(1,2,3...100)

In other words and slightly more complex - "You're looking at widgets found in both category 9 AND 10 user, widgets that appear in category 9 & 10 also appear in categories 1,2,3..100".

Hope that makes sense.

Thanks in advance, C

12:53 pm on July 21, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Dec 20, 2004
posts:2377
votes: 0


You can use a nested select statement, something like this:

select distinct(category_id) from tbl where widget_id IN (select widget_id from tbl_widgets where...)

Not sure if this helps you. But it would simplify the code if you are able to pull them from another table based on some logic/conditions...

1:07 pm on July 21, 2008 (gmt 0)

Junior Member

10+ Year Member

joined:Mar 17, 2005
posts: 109
votes: 0


Thanks for the response; sadly 4.1.2 doesn't support nested queries though (I think).