select * from a,b与select * from a inner join b 的取数方式和执行效率有什么
1个回答

(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)

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

注意:外连接不一定非要有外键约束

1: left outer join --不能用left out join

左表中的记录全部会出现在结果集中,匹配不上的显示NULL

2: right outer join

右表中的记录全部会出现在结果集中,匹配不上的显示NULL

3: full outer join|full join --不能用full out join

返回两个表中的匹配和不匹配的所有记录.