如果第一个返回多个值,那么这是一个SQL查询失败 -
SELECT subject
FROM a_batchcourse_subject AS s
WHERE (batchcourse =
(SELECT batchcourse
FROM a_course_batchcourse AS b
WHERE (course = 'Course 1')))
在第一个查询可能返回多个值的情况下,编写此查询的正确方法是什么?
答案 0 :(得分:5)
您希望sql中的IN
不是=
SELECT subject
FROM a_batchcourse_subject AS s
WHERE batchcourse IN
(SELECT batchcourse
FROM a_course_batchcourse AS b
WHERE course = 'Course 1')
答案 1 :(得分:4)
JOIN
比IN
子句
SELECT s.subject
FROM a_batchcourse_subject s
INNER JOIN a_course_batchcourse b
on s.batchcourse = b.batchcourse
WHERE (b.course = 'Course 1')