对于array = [1,1,1,2]
,DB表具有ids-1,2
的条目。
查询 - > “SELECT * FROM table WHERE id in array"
只返回两行。
有没有办法让它返回4行?
答案 0 :(得分:0)
您可以使用UNION ALL
建立一个内联表格,然后INNER JOIN
您的表格:
SELECT t2.*
FROM (
SELECT 1 AS v UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 2
) AS t1
INNER JOIN mytable AS t2 ON t1.v = t2.id