1,左连接时,第一个表中的所需的数据全要,第二个表中如果没有相应匹配的数据则补null。

2,右连接时,第二个表中的所需数据全要,第一个表中如果没有相应匹配的数据则补null。

3,内连接时,只有第一个表和第二个表中有相应数据匹配时才要,如果其中一个表没有相应的数据匹配则不要。

4,union可以连接2个select的查询结果,前提是所查询的列数相同,且查询的字段以第一个表的字段为字段名,查询结果去除相同行的数据,如果使用union all则可以达到外连接,即获取所有行的数据(包括相同的行)的结果。

<?php

select hid,t1.tname as hname,mres,gid,t2.tname as gname,matime from m left join t as t1 on m.hid=t1.tid left join t as t2 on m.gid=t2.tid; //左连接


select id,sum(num) from (select id,num from a union all select id,num from b) as tmp group by id;//union连接














?>