select * from StudySQL.dbo.id_name n
inner join StudySQL.dbo.id_sex s
on n.id=s.id
and s.sex= f
select * from StudySQL.dbo.id_name n
inner join StudySQL.dbo.id_sex s
on n.id=s.id
where s.sex= f
结果完全一样。 那么它们之间有什么区别吗?
Add
我做了几次更有趣的尝试
select * from StudySQL.dbo.id_name n
1 | baby
3 | alice
select * from StudySQL.dbo.id_class c
1 | math
3 | physics
3 | english
4 | chinese
select * from StudySQL.dbo.id_name n
left join StudySQL.dbo.id_class c
on n.name= alice
name id id class
baby 1 NULL NULL
alice 3 1 math
alice 3 3 physics
alice 3 3 english
alice 3 4 chinese
select * from StudySQL.dbo.id_name n
left join StudySQL.dbo.id_class c
on n.name= baby
name id id class
baby 1 1 math
baby 1 3 physics
baby 1 3 english
baby 1 4 chinese
alice 3 NULL NULL
select * from StudySQL.dbo.id_name n
left join StudySQL.dbo.id_class c
on n.name<>
name id id class
baby 1 1 math
baby 1 3 physics
baby 1 3 english
baby 1 4 chinese
alice 3 1 math
alice 3 3 physics
alice 3 3 english
alice 3 4 chinese
So I thinnk it s reasonable to say, the on clause decides which rows should be joined. While the where clause decides which rows should be returned.
如果情况属实,<强势>我认为最好在条款中写明详细的限制,这样需要加入的行就更少。 强势>加入是一个昂贵的操作。