mysql把两个表语句_select语句将两个表连在一起查询---MySQL

select语句将两个表连在一起查询

MSSQL中: select * from a join b on a.a=b.b 是横向的 select abc from a union all select abc from b 是纵向的.

------------------------------

(1)连接

select * from table1,table2

等价于

select * from table1 cross join table2

select * from table1,table2 where table1.row=table2.row

(2)自连接

select * from emploly e1 ,emploly e2

select e1.name,e2.name from employ e1,employ e2

where e1.name=e2.name

(3)内连接(inner join)

select stuname as '姓名',classname as '班级' from student inner join

class on student.stuid=class.stuid

inner join '表名' on 条件 --连接多个表

它等价于:

select stuname as '姓名',classname as '班级'

from student,class

where student.stuid=class.stuid

(4)外连接:(outer join)

允许限制一张表中的行,而不限制另外一张表中的行。

注意:外连

你可能感兴趣的:(mysql把两个表语句)