当前位置:网站首页>Database daily question --- day 10: combine two tables
Database daily question --- day 10: combine two tables
2022-06-12 22:07:00 【InfoQ】
One 、 Problem description
Person+-------------+---------+
| Name | type |
+-------------+---------+
| PersonId | int |
| FirstName | varchar |
| LastName | varchar |
+-------------+---------+
personId Is the primary key column of the table .
This table contains some people's ID And their last and first names .
Address+-------------+---------+
| Name | type |
+-------------+---------+
| AddressId | int |
| PersonId | int |
| City | varchar |
| State | varchar |
+-------------+---------+
addressId Is the primary key column of the table .
Each row of the table contains a ID = PersonId Information about people's cities and states .
PersonpersonIdAddressnullTwo 、 Subject requirements
Examples
Input :
Person surface :
+----------+----------+-----------+
| personId | lastName | firstName |
+----------+----------+-----------+
| 1 | Wang | Allen |
| 2 | Alice | Bob |
+----------+----------+-----------+
Address surface :
+-----------+----------+---------------+------------+
| addressId | personId | city | state |
+-----------+----------+---------------+------------+
| 1 | 2 | New York City | New York |
| 2 | 3 | Leetcode | California |
+-----------+----------+---------------+------------+
Output :
+-----------+----------+---------------+----------+
| firstName | lastName | city | state |
+-----------+----------+---------------+----------+
| Allen | Wang | Null | Null |
| Bob | Alice | New York City | New York |
+-----------+----------+---------------+----------+
explain :
There is no personId = 1 The address of , So their cities and States return null.
addressId = 1 Contains personId = 2 Address information for .
Investigate
1. Table joins
2. It is recommended to use time 10~25min
3、 ... and 、 Problem analysis
SQL- A inner join B: Internal connection , intersect
- A left join B: The left outer join , take A All ,B There is no corresponding value , Then for
null
- A right join B: Right connection , take B All ,A There is no corresponding value , Then for
null
- A full outer join B: Full outer join , Union and collection , There is no corresponding value for each other
null
PersonAddress readily solved Four 、 coded
select p.firstName,p.lastName,a.city,a.state
from Person p
left join Address a on p.personId=a.personId
5、 ... and 、 test result


边栏推荐
- 建立高可用的数据库
- 经济学人聚焦WTO MC12:数字经济或成重要议题
- Ansible Roles-项目案例(四)
- [C language] data type occupation
- How to develop programming learning with zero foundation during college
- Design and practice of Hudi bucket index in byte skipping
- What is your understanding of thread priority?
- PCB package download website recommendation and detailed usage
- 脱颖而出!OceanBase 入选 2021“科创中国”开源创新榜单
- SQL tuning guide notes 8:optimizer access paths
猜你喜欢

Ansible playbook和Ansible Roles(三)

PE installation win10 system

Build a highly available database

回文链表及链表相交问题(和心怡的人相交)你真的会了吗?
![[data analysis] data clustering and grouping based on kmeans, including Matlab source code](/img/76/deec6cf60c0d02e99ebc3e21d3b8a4.png)
[data analysis] data clustering and grouping based on kmeans, including Matlab source code

NiO User Guide

Mr. Sun's version of JDBC (21:34:25, June 12, 2022)

Compiling process of OpenSSL and libevent on PC

Yyds dry inventory insider news: Series high-frequency interview questions, worth a visit!

MySQL介绍和安装(一)
随机推荐
Cloning PDB with ADG standby
Logstash timestamp converted to UNIX nanosecond nano second time
Npoi create word
SQL tuning guide notes 17:importing and exporting optimizer statistics
The kotlin coroutine -- coroutine context and exception propagation
[Jianzhi offer simple] Jianzhi offer 06 Print linked list from end to end
MySQL介绍和安装(一)
SQL调优指南笔记13:Gathering Optimizer Statistics
How to specify your webpage's language so Google Chrome doesn't offer to translate it
How to write a vscode plug-in by yourself to realize plug-in freedom!
MySQL体系结构及基础管理(二)
Economist focuses on WTO MC12: digital economy may become an important issue
Open source background management system suitable for outsourcing projects
【数据分析】基于 kmeans实现数据聚类分组含Matlab源码
Role of volatile keyword
【概率论与数理统计】期末复习抱佛脚:公式总结与简单例题(完结)
多线程模型下的生产者消费者模式
NiO User Guide
Oracle livelabs experiment: introduction to Oracle Spatial
接口测试工具apipost3.0版本对于流程测试和引用参数变量