当前位置:网站首页>SQL multi table query
SQL multi table query
2022-07-27 15:58:00 【Not enough to eat】
Multi-table query
basic sql sentence
SELECT < Target field > FROM < Database table > WHERE < Query criteria > GROUP BY < Group by > ORDER BY < Arrangement basis >
Multi-table query
- Internal connection : Return the data that satisfies the connection condition
Format :SELECT < Target field > FROM <INNER JOIN+ Table name +ON+ Connection condition > WHERE < Query criteria >
Be careful : Clarify the relationship between tables , Find out what data from which tables , What are the connection conditions between tables
Patients with a : Double table query

Example 2 : Multi-table query
a sys_user user_name => user_id dept_id
b sys_user_role user_id => role_id
c sys_role role_id => role_name
d sys_role_dept role_id => dept_id
e sys_dept dept_id => dept_name parent_id dept_name
f sys_dept parent_id => dept_name
SELECT
a.user_name,
a.user_id,
a.dept_id,
b.role_id,
c.role_name,
e.dept_name,
f.dept_name
FROM
sys_user AS a
INNER JOIN sys_user_role AS b ON b.user_id = a.user_id
INNER JOIN sys_role AS c ON c.role_id = b.role_id
INNER JOIN sys_dept AS e ON e.dept_id = a.dept_id
INNER JOIN sys_dept AS f ON f.dept_id = e.parent_id
WHERE
a.user_name = 'zjzsqxyf01'
External connection : The external connection lists not only the rows that match the connection conditions , Instead, list the left table ( Left outer connection )、 Right table ( Right outer connection ) Or two tables ( When fully externally connected ) All data rows that meet the search criteria in the
(1) Left connection : Return all data in the left table
Format :SELECT < Target field > FROM <LEFT JOIN+ Table name +ON+ Connection condition > WHERE < Query criteria >

(2) The right connection : Return all data in the right table
Format :SELECT < Target field > FROM <RIGHT JOIN+ Table name +ON+ Connection condition > WHERE < Query criteria >

(3) Full connection : On the basis of equivalent connection, add the unmatched data of the left table and the right table
Format :SELECT < Target field > FROM <FULL JOIN+ Table name +ON+ Connection condition > WHERE < Query criteria >

- Natural join : Based on all columns with the same fields in two tables , Return the data that meets the query conditions in the two tables
边栏推荐
- Stock account opening commission discount, stock trading account opening which securities company is good, is online account opening safe
- 网络设备硬核技术内幕 路由器篇 22
- [TensorBoard] OSError: [Errno 22] Invalid argument处理
- JS find the maximum and minimum values in the array (math.max() method)
- 折半查找
- JS operation DOM node
- Insert sort directly
- C语言实现字节流与十六进制字符串的相互转换
- UDP 的报文结构和注意事项
- [Yunxiang book club issue 13] packaging format and coding format of audio files
猜你喜欢

Interview focus - TCP protocol of transport layer

drf使用:get请求获取数据(小例子)

Spark 3.0 adaptive execution code implementation and data skew optimization

First acquaintance with MySQL database

DRF学习笔记(四):DRF视图

Spark 3.0 DPP implementation logic

C语言:函数栈帧

Push down of spark filter operator on parquet file

初识结构体

Three uses of static keyword
随机推荐
接连取消安富利/文晔/世平代理权,TI到底打的什么算盘?
C语言:三子棋游戏
初识MySQL数据库
Go language slow start - package
一款功能强大的Web漏洞扫描和验证工具(Vulmap)
[正则表达式] 匹配分组
Breaking through soft and hard barriers, Xilinx releases Vitis unified software platform for developers
禁令之下,安防巨头海康与大华的应对之策!
Inter thread wait and wake-up mechanism, singleton mode, blocking queue, timer
兆骑科创创业大赛策划承办机构,双创平台,项目落地对接
[sword finger offer] interview question 41: median in data flow - large and small heap implementation
C language: custom type
【云享读书会第13期】视频文件的编码格式
Binder初始化过程
Leetcode-1: sum of two numbers
Spark troubleshooting finishing
On juicefs
To meet risc-v challenges? ARM CPU introduces custom instruction function!
为应对RISC-V挑战?Arm CPU引入自定义指令功能!
C语言:自定义类型