0

例如:

SELECT tb1.column1, tb1.column2
FROM table1 AS tb1
WHERE tb1.column1 = (SELECT tb2.column2 FROM table2 As tb2)

但是……子查询可能有不止一个结果。如果有 3 个结果来自子查询,我该如何处理?

4

2 回答 2

2

用于IN此。

IN可以处理多个值,而=只能保存一个。

SELECT tb1.column1, tb1.column2
FROM table1 AS tb1
WHERE tb1.column1 IN (SELECT tb2.column2 FROM table2 As tb2)

或者另一种方法是使用JOIN更优选的方法,

SELECT  DISTINCT tb1.column1, tb1.column2
FROM    table1 AS tb1
        INNER JOIN table2 b
            ON tb1.column1 = b.column2
于 2013-03-30T16:06:28.437 回答
1

您需要使用in而不是=

SELECT tb1.column1, tb1.column2
FROM table1 AS tb1
WHERE tb1.column1 in (SELECT tb2.column2 FROM table2 As tb2)
于 2013-03-30T16:06:58.740 回答