【Leetcode】CombineTwoTables
题目:
table: person
+————-+———+
| column name | type |
+————-+———+
| personid | int |
| firstname | varchar |
| lastname | varchar |
+————-+———+
personid is the primary key column for this table.
table: address
+————-+———+
| column name | type |
+————-+———+
| addressid | int |
| personid | int |
| city | varchar |
| state | varchar |
+————-+———+
addressid is the primary key column for this table.
write a sql query for a report that provides the following information for each person in the person table, regardless if there is an address for each of those people:
firstname, lastname, city, state
思路:
考察join语句
inner join是两表交集
outer join是两表除了交集之外的部分,left是不管左边表满不满足on的条件都在结果中,right同理,full是两表并集
算法:
select firstname,lastname,city,state from person p left outer join address a on p.personid=a.personid
上一篇: WPF学习笔记(1):DataGrid单元格实现逐键过滤功能
下一篇: C++ 小型超市管理系统