当前位置:网站首页>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


边栏推荐
- June training (day 11) - matrix
- Redis optimization
- Pat grade A - 1167 Cartesian tree (30 points) (buildtree + level traversal)
- Configuring Dingding notification of SQL audit platform archery
- SQL调优指南笔记13:Gathering Optimizer Statistics
- Cloning PDB with ADG standby
- What is the race condition? How do you find and solve the competition?
- SQL调优指南笔记8:Optimizer Access Paths
- SQL tuning guide notes 14:managing extended statistics
- SQL tuning guide notes 16:managing historical optimizer statistics
猜你喜欢

Oracle livelabs experiment: introduction to Oracle Spatial

SQL query list all views in SQL Server 2005 database - SQL query to list all views in an SQL Server 2005 database

MySQL介绍和安装(一)

Ansible playbook和Ansible Roles(三)

MySQL architecture and basic management (II)
![[image denoising] image denoising based on trilateral filter with matlab code](/img/f2/770a0e2938728e731c18c0a66f7c12.png)
[image denoising] image denoising based on trilateral filter with matlab code

About the solution to "the application cannot start normally 0xc00000022" after qt5.15.2 is installed and qtcreator is started

User guide for JUC concurrency Toolkit

PCB封装下载网站推荐及其详细使用方法

Dolphin-2.0.3 cluster deployment document
随机推荐
How to perform disaster recovery and recovery for kubernetes cluster? (22)
Is it safe to open an account in tonghuashun? How to open an account
SQL tuning guide notes 16:managing historical optimizer statistics
How to prevent phishing emails? S/mime certificate to help!
[simple] 155 Minimum stack
User guide for JUC concurrency Toolkit
[data analysis] data clustering and grouping based on kmeans, including Matlab source code
生成小程序菊花码(生成菊花码、更换中间logo、更改图片尺寸,加文字)
【图像去噪】基于三边滤波器实现图像去噪附matlab代码
The 2023 campus recruitment officially opened! Oceanbase would like to make an interview with you this spring
What is your understanding of thread priority?
Ansible playbook和Ansible Roles(三)
February 27th
接口测试工具apipost3.0版本对于流程测试和引用参数变量
Things about the kotlin collaboration process - pipeline channel
Ansible foundation and common modules (I)
PCB封装下载网站推荐及其详细使用方法
jsonUtils
Exception encountered by selenium operation element
talent showing itself! Oceanbase was selected into the 2021 "sci tech innovation China" open source innovation list