关于表的连接,有cross join, inner join, left join , right join几种连接方式
1.cross join 笛卡尔连接,两个表的所有字段记性笛卡尔成绩,比如表1中m条数据,表2中n条数据,则结果数量是m*n
用法 select * from table1 cross join table2
2.inner join内联接,用on来指定两张表需要比较的字段,最终结果只显示满足条件的数据
select * from table1 inner join table2 on table1.id1 = table2.id2
3.left join 左连接,在内联接的基础上,把左表中满足条件的数据都显示出来,但结果中右表的部分数据为null
4.right join 右连接,跟左连接相反
5.outer join 外连接,左连接和右连接的并集(合集),mysql不支持全连接的写法,但可以用union联合左连接,右连接的结果来代替