Alex Rivera | Logout

MySQL WHERE <multiple-column> IN <subquery>

Asked 2012-07-09T10:41:13.587
30

Is there a way (without JOIN) to use the WHERE clause on 2 columns (OR) IN a subquery? Currently, I'm doing

WHERE 'col1' IN
(
    SELECT id FROM table
) OR 'col2' IN
(
    SELECT id FROM table
)

And I'm sure I can do better :) . i've also tried WHERE ('col1', 'col2') IN <subquery> but MySQL says: Operand should contain 2 column(s)

Thanks for your help.

Edit: By "No join", I mean I'm alreeady making many joins: http://pastebin.com/bRfD21W9, and as you can see, the subqueries are on another table.

Edit
Report

1 Answer

0

You can try below query:

select name from user_details where groupid IN ( select g_id from user_groups ) OR  cityid IN ( select c_id from user_cities );  

Hope this help.

answered 2012-07-09T10:58:08.883

Your Answer