我有两个表,例如:
table_1 (id_t1,id_t2,...);
table_2 (id_t2,...);
我知道 table_1 的 id_t1 ,我需要按 id_t2 的值从 table_1 获取所有行>带有联接表2。我可以在MariaDB中对一个查询执行此操作吗?
现在我可以这样做:
select id_t2 from table_1;
select *
from table_1 left join table_2 on table_1.id_t2=table_2.id_t2
where id_t2=the result of past query;
答案 0 :(得分:1)
尝试使用IN
语句
SELECT *
FROM table_1 LEFT JOIN table_2 ON table_1.id_t2=table_2.id_t2
WHERE table1.id_t2 IN (select tAux.id_t2 from table_1 as tAux);