0

这是我的 sql 数据提琴手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
4

2 回答 2

1

如果您要从两个表中查找匹配行,则只需替换LEFT JOININNER 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
于 2013-09-18T06:52:02.237 回答
0

您的查询按预期工作。会不会是你在混合 ID 和 CURR_ID?

于 2013-09-18T06:58:02.457 回答