0

我有一个返回 3 列的子查询。我无法摆脱它们。我只想将其中一列用于父查询。

例如。

SELECT * FROM table_a WHERE id = (SELECT a,id,b FROM table_b LIMIT 1);

我只想idtable_b.

我正在寻找类似的东西:

SELECT * FROM table_a WHERE id = (SELECT a,id,b FROM table_b LIMIT 1)[id];

我将如何做到这一点?

4

4 回答 4

3

怎么样:

SELECT * FROM table_a WHERE id =
(select id from
 (SELECT a,id,b FROM table_b LIMIT 1)a);
于 2012-10-17T06:39:04.327 回答
0
SELECT * 
FROM table_a 
WHERE id IN
    (
        SELECT a FROM tableB limit 1
        UNION
        SELECT id FROM tableB limit 1
        UNION
        SELECT b FROM tableB limit 1
    ) 
于 2012-10-17T06:00:58.087 回答
0
SELECT * FROM table_a, (SELECT a,id,b FROM table_b LIMIT 1) temp_b where table_a.id = temp_b.id;

这个结果符合你的想法吗?

于 2012-10-17T06:03:47.273 回答
0

我认为实现这一目标的最佳方法是:

SELECT * 
FROM table_a
inner join 
 (
       SELECT a as id FROM tableB
        UNION
        SELECT id FROM tableB
        UNION
        SELECT b as id FROM tableB
) tempB on (table_a.id=tempB.id)
于 2012-10-17T06:10:06.897 回答