Tester232323 Tester232323 - 1 year ago 153
SQL Question

MySQL sub query with multiple columns

After some research I now understand I cannot return multiple columns from a subquery. What can I do instead?

SELECT * FROM `users` WHERE `id` IN (SELECT `id1`, `id2` FROM `ids` WHERE `location` = 1)

The result is
#1241 - Operand should contain 1 column(s)

Answer Source

Try this:

Select users.* 
  from users 
    join ids 
   on users.id IN(ids.id1, ids.id2)
   and ids.location = 1;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download