我有一个返回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];
我将如何做到这一点?
答案 0 :(得分:3)
这是怎么回事:
SELECT * FROM table_a WHERE id =
(select id from
(SELECT a,id,b FROM table_b LIMIT 1)a);
答案 1 :(得分: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
)
答案 2 :(得分:0)
SELECT * FROM table_a, (SELECT a,id,b FROM table_b LIMIT 1) temp_b where table_a.id = temp_b.id;
这个结果与你的想法相符吗?
答案 3 :(得分: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)