SQL JOIN

INNER JOIN:获取两个表中字段匹配关系的记录

select xxx from table1 t1 inner join table2 t2 on t1.xx=t2.xx;

inner join可以省略,等同于:

select xxx from table1 t1,table2 t2 where t1.xx=t2.xx;

LEFT JOIN:获取左表所有记录,即使右表没有对应匹配的记录

select xxx from table1 t1 left join table2 t2 on t1.xx=t2.xx;

RIGHT JOIN:获取右表所有记录,即使左表没有对应匹配的记录

select xxx from table1 t1 right join table2 t2 on t1.xx=t2.xx;
posted @ 2018-12-05 14:50  这个人在加班  阅读(239)  评论(0编辑  收藏  举报