Mysql中on,in,as,where的区别

答:Where查询条件,on内外连接时候用,as作为别名,in查询某值是否在某条件里

创建2个表:student,score

student:Mysql中on,in,as,where的区别_第1张图片

 score:Mysql中on,in,as,where的区别_第2张图片

where

SELECT * FROM student WHERE s_sex='男'

Mysql中on,in,as,where的区别_第3张图片

例如:on

SELECT * FROM student LEFT JOIN score on student.s_id=score.s_id;

Mysql中on,in,as,where的区别_第4张图片

on和where组合:

SELECT * FROM student LEFT JOIN score on student.s_id=score.s_id WHERE s_name='赵雷' 

Mysql中on,in,as,where的区别_第5张图片

 

例如:in

SELECT * FROM score WHERE s_id in (SELECT s_id FROM student WHERE s_name='赵雷')

 Mysql中on,in,as,where的区别_第6张图片

as

select * from score as a LEFT JOIN student as b on a.s_id=b.s_id where s_name='赵雷'

Mysql中on,in,as,where的区别_第7张图片 

你可能感兴趣的:(mysql,mysql)