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;
原文地址:https://www.cnblogs.com/diffx/p/10070899.html