我有sql查询:
SELECT DISTINCT project_id
FROM projects
WHERE (meta_key = "Project Name" AND meta_value LIKE '%t%' )
返回
project_id
251
299
302
319
317
307
310
312
371
364
365
366
368
我还有另一个疑问:
SELECT DISTINCT project_id
FROM tags
WHERE (tag LIKE '%t%')
返回:
project_id
251
我尝试将这两个语句与IN
语句结合起来,以便到达那里。
SELECT DISTINCT project_id
FROM projects
WHERE (meta_key = "Project Name" AND meta_value LIKE '%t%' )
IN (SELECT DISTINCT project_id
FROM tags
WHERE (tag LIKE '%t%'))
但是,我没有得到任何结果。
project_id
我想我应该
project_id
251
我在这里正确使用IN
声明吗?如果不是我应该使用哪个工具来完成此任务。谢谢。
答案 0 :(得分:2)
只需将 project_id 分配给IN()
子句表达式即可。现在,WHERE
评估其他...
WHERE (meta_key = 'Project Name' AND meta_value LIKE '%t%' )
AND project_id IN (SELECT DISTINCT project_id
FROM tags
WHERE (tag LIKE '%t%'))
条件的布尔逻辑, False 或 True 永远不会等同于三位整数。< / p>
NSItemProvider