这是我的sql数据fiddler http://sqlfiddle.com/#!2/63178/1。我的查询出了什么问题?
SELECT DISTINCT curr.id,curr.curr_tittle, curr.curr_desc
FROM wp_curriculum curr LEFT JOIN (SELECT DISTINCT * FROM wp_curriculum_topic WHERE curr_topic IN (4,12)) AS A ON A.curr_id = curr.id ORDER BY A.id
答案 0 :(得分:1)
如果您要查找表中的匹配行,则只需将LEFT JOIN
替换为INNER JOIN
,否则您的sql查询将显示LEFT JOIN条件的预期结果。
使用INNER JOIN的SQL查询:
SELECT DISTINCT curr.id,curr.curr_tittle, curr.curr_desc FROM wp_curriculum curr INNER JOIN (SELECT DISTINCT * FROM wp_curriculum_topic WHERE curr_topic IN (4,12)) AS A ON curr.id = A.curr_id ORDER BY A.id
答案 1 :(得分:0)
您的查询按预期工作。可能是你正在混合ID和CURR_ID?