Tester232323
Tester232323

Reputation: 301

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)

Upvotes: 0

Views: 421

Answers (1)

Priyansh Goel
Priyansh Goel

Reputation: 2660

Try this:

Select users.* 
  from users 
    join ids 
   on users.id IN(ids.id1, ids.id2)
   and ids.location = 1;

Upvotes: 1

Related Questions