/*交叉链接,笛卡儿积*/
select *
from student,sc;
/********验证数量*/
select count(*),29*9
from student,sc;
select count(*)
from sc;
/*另一种写法*/
select *
from student cross join sc;
/*等值连接*/
select student.sno,sname,cno,grade
from student,sc
where student.sno=sc.sno
and ssex='女';
/*第二种写法*/
select student.sno,sname,cno,grade
from student join sc
on student.sno=sc.sno
where ssex='女';
/*不去掉重复列*/
select *
from student cross join sc
on student.sno=sc.sno
where ssex='女';
/*自然连接*/
select student.sno,sname,cno,grade
from student natural join sc
/*on student.sno=sc.sno 不用写条件*/
where ssex='女';
/*一个表自己与自己做自然连接还是它自己
但不能有null值,两个null不能判断大小*/
/*左外连接*/
select *
from student left outer join sc on student.sno;
MySQL sql语句连接查询笔记
最新推荐文章于 2025-02-26 10:40:06 发布