我有一个返回 3 列的子查询。我无法摆脱它们。我只想将其中一列用于父查询。
例如。
SELECT * FROM table_a WHERE id = (SELECT a,id,b FROM table_b LIMIT 1);
我只想id
从table_b
.
我正在寻找类似的东西:
SELECT * FROM table_a WHERE id = (SELECT a,id,b FROM table_b LIMIT 1)[id];
我将如何做到这一点?
我有一个返回 3 列的子查询。我无法摆脱它们。我只想将其中一列用于父查询。
例如。
SELECT * FROM table_a WHERE id = (SELECT a,id,b FROM table_b LIMIT 1);
我只想id
从table_b
.
我正在寻找类似的东西:
SELECT * FROM table_a WHERE id = (SELECT a,id,b FROM table_b LIMIT 1)[id];
我将如何做到这一点?
怎么样:
SELECT * FROM table_a WHERE id =
(select id from
(SELECT a,id,b FROM table_b LIMIT 1)a);
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
)
SELECT * FROM table_a, (SELECT a,id,b FROM table_b LIMIT 1) temp_b where table_a.id = temp_b.id;
这个结果符合你的想法吗?
我认为实现这一目标的最佳方法是:
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)