关联查询

等值连接、左连接、右连接的使用情况?

等值连接是查询两个表中联结字段相等的记录
eg:
select * from table1 inner join table2 on table1.id = table2.id;
select * from (table1 inner join table2 on table1.id = table2.id) inner join table3 on table1.id = table3.id;

左连接是查询左表的所有记录和右表中联结字段相等的记录
eg:
select * from table1 left join table2 on table1.id = table2.id;
select * from table1 left join table2 on table1.id = table2.id left join table3 on table1.id = table3.id;

右连接是查询右表的所有记录和左表中联结字段相等的记录
eg:
select * from table1 right join table2 on table1.id = table2.id;
select * from table1 right join table2 on table1.id = table2.id right join table3 on table1.id = table3.id;

你可能感兴趣的:(学习)