具有多列的MySQL子查询

时间:2016-05-10 23:09:01

标签: mysql

经过一些研究后,我现在明白我不能从子查询中返回多个列。我该怎么做呢?

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

结果为#1241 - Operand should contain 1 column(s)

1 个答案:

答案 0 :(得分:1)

试试这个:

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