连接查询

union

同时查询多个表,去除重复部分

eg:

select 1 one,2 two
union
SELECT 2 one,2 englich;

left join

左外连接查询

eg:

select  *  from  table1  left join  table2  on  table1.id = table2.pId;

备注:以左表为主表,左外连接的结果集合包括左表的所有记录和右表中满足条件的记录,结果集中那些不符合连接条件的来源于右表的列值为NULL

right join

右外连接查询

eg:

select  *  from  table1  right  join  table2  on  table1.id = table2.pId;

备注:以右表为主表,右外连接的结果集合包括右表的所有记录和左表中满足条件的记录,结果集中那些不符合连接条件的来源于右表的列值为NULL

inner join

内连接查询

eg:

  隐式:SELECT * from table1,table2 where [condition]

  显式:SELECT * from table1 INNER JOIN table2 ON [关联条件] where [其他筛选条件]

备注:内连接和等值链接作用一样,查询到的都是两个表的交集数据,查询不到交集以外的数据

posted @ 2022-08-23 21:51  李蚊秀香  阅读(37)  评论(0编辑  收藏  举报