我在调试此查询时遇到问题,这会给我带来错误的结果...... 2条记录而不是1条记录。
以下是查询:
SELECT DISTINCT t1.*, t2.filterid as filterid2
FROM ( SELECT DISTINCT a.*, f.`filterid`
FROM adds a
JOIN adds_filters f
ON a.`addid` = f.`addid`
WHERE a.`catid` = 1
AND f.`filterid` = 67 ) t1
JOIN ( SELECT DISTINCT a.`addid`,f.`filterid`
FROM adds a
JOIN adds_filters f
ON a.`addid` = f.`addid`
WHERE a.`catid` = 1
AND f.`filterid` = 68 ) t2
JOIN ( SELECT DISTINCT a.`addid`,f.`filterid`
FROM adds a
JOIN adds_filters f
ON a.`addid` = f.`addid`
WHERE a.`catid` = 1
AND f.`filterid` = 158 ) t3
ON t1.addid = t2.addid
由于表格相当长,这里是fiddle
任何帮助都将深受赞赏
问候,约翰
答案 0 :(得分:1)
我认为你在最后一行中想要的是
ON t1.addid = t2.addid and t2.addid =t3.addid;