最近在学sql的join方法时候,用到了on的关键字,因此看了一下和where的区别,特意记在这里,以备之后遗忘。
person表(id, name, age)
account表(id, account)
select * FROM person p inner join account a on p.id = a.id;
结果一
select * FROM person p inner join account a on p.id = a.id and p.id != 1;
结果二
select * FROM person p inner join account a on p.id = a.id where p.id != 1;
结果三
select * FROM (select * FROM person where id != 1) p inner join account on account.id = p.id;
select * FROM person p left join account a on p.id = a.id ;
结果一
select * FROM person p left join account a on p.id = a.id and p.id != 1;
结果二
select * FROM person p left join account a on p.id = a.id where p.id != 1;
结果三
select * FROM person p inner join account a on p.id = a.id;
结果一
select * FROM person p right join account a on p.id = a.id and p.id != 1;
结果二
select * FROM person p right join account a on p.id = a.id and p.id != 1;
结果三