简体   繁体   English

在IN Clause Mysql中使用GROUP_CONCAT结果

[英]Use GROUP_CONCAT result in IN Clause Mysql

i have aq query which returns comma sepreted integers like 我有一个aq查询,它返回逗号拼写的整数,如

select GROUP_CONCAT(ids) from table2

now i want to use that result in another query like 现在我想在另一个查询中使用该结果

select * from table1 where column in (select GROUP_CONCAT(ids) from table2)

in this case it will consider only forst value in IN clause. 在这种情况下,它只考虑IN子句中的最低值。

I agree with @Alma that this can't be done with IN, you might be able to do it with FIND_IN_SET , but if you can do it with IN it's probably a better approach : 我同意@Alma,这不能用IN完成,你可以用FIND_IN_SET来做 ,但如果你能用IN做它可能是一个更好的方法:

SELECT *
FROM table1
WHERE find_in_set(ids, (
      SELECT GROUP_CONCAT(ids)
      FROM table2
      )) != 0;

sqlfiddle demo sqlfiddle演示

Any special reason not using a join and using a sub query 任何不使用连接和使用子查询的特殊原因

select * from table1 t1
JOIN table2 t2 on (t2.column = t1.ids)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM