SQL语句面试问答(五)
解释过明各种Joins
图表 | 语句 |
select <select_list> from table A left join table B on A.key=B.key 即使右表中没有匹配,也从左表返回所有行 | |
select <select_list> from table A right join table B on A.key=B.key 即使左表中没有匹配,也从右表返回所有行 | |
select <select_list> from table A inner join table B on A.key=B.key 如果表中有至少一个匹配,则返回行,与join相同 | |
select <select_list> from table A left join table B on A.key=B.key where B.key is null | |
select <select_list> from table A right join table B on A.key=B.key where A.key is null | |
select <select_list> from table A full outer join table B on A.key=B.key full on:只要其中一个表中存在匹配,则返回行 | |
select <select_list> from table A full outer join table B on A.key=B.key where A.key is null or B.key is null |
整理面试过程中的测试问答,常看常新,多多学习!有些问题是从其他人那里转载而来,会在文章下面注明出处,希望大家多多支持~~