现有三张表,表一,表二,表三,表二和表三无关联,根据条件 表一.id=表二.id
表一.id=表三.id 如何用一条查询语句表二,表三的所有数据,且不能查出来的两张表的数据
一 一对应合成一条数据。
如何用一条查询语句表二,表三的所有数据,且不能查出来的两张表的数据一 一对应合成一条数据。你这个描述从逻辑上就说不通,既要查出所有数据又要不能查出的数据合成一条数据。你先告诉我怎么实现不能查出来的数据怎么合成一条数据。
根据所问猜想你的要求,给出答案:
1、查询表二表三的所有数据,并且关联了表一的合并为一条数据,没有关联的单独作为一条数据
select b.*,c.* from 表1 a full join 表2 b on a.id = b.id
full join 表3 c on a.id = c.id
使用内连接 select a.*,b.* from a inner join b on a.id=b.id
SELECT
t1.id,
t1.字段*,
t2.字段*,
t3.字段*
FROM
t1
LEFT JOIN t2 ON t1.id = t2.id
LEFT JOIN t3 ON t1.id = t3.id
select table2.* from table1 right join table2 on table2.id=table1.id union select table3.* from table1 right join table3 on table3.id=table1.id
使用内连接,再尝试聚合 (select b.* from a inner join b on a.id=b.id ) union (select c.* from a inner join c on a.id=c.id )