当前位置:网站首页>Database SQL language 02 connection query
Database SQL language 02 connection query
2022-07-03 01:12:00 【Super brother 1986】
JOIN
Example :
/* Link query If you need data from multiple data tables to query , Multiple queries can be implemented through join operators Internal connection inner join Query the intersection of the result sets in two tables External connection outer join The left outer join left join ( Take the left table as a benchmark , The table on the right matches one by one , It doesn't match , Return the record in the left table , The table on the right shows NULL fill ) Right connection right join ( Take the right table as a benchmark , The table on the left matches one by one , It doesn't match , Return the record in the right table , On the left side of the table NULL fill ) Equivalent connection and non equivalent connection Self join */
-- Query the information of the students who took the exam ( Student number , The student's name , Account No , fraction )
SELECT * FROM student;
SELECT * FROM result;
/* Ideas : (1): Analyze requirements , Make sure that the columns of the query come from two classes ,student result, Link query (2): Determine which connection query to use ?( Internal connection ) */
SELECT s.studentno,studentname,subjectno,StudentResult
FROM student s
INNER JOIN result r
ON r.studentno = s.studentno
-- The right connection ( Can also be realized )
SELECT s.studentno,studentname,subjectno,StudentResult
FROM student s
RIGHT JOIN result r
ON r.studentno = s.studentno
-- Equivalent connection
SELECT s.studentno,studentname,subjectno,StudentResult
FROM student s , result r
WHERE r.studentno = s.studentno
-- Left connection ( I checked all the students , Those who don't take exams will find out )
SELECT s.studentno,studentname,subjectno,StudentResult
FROM student s
LEFT JOIN result r
ON r.studentno = s.studentno
-- Check out the absent students ( Left link application scenario )
SELECT s.studentno,studentname,subjectno,StudentResult
FROM student s
LEFT JOIN result r
ON r.studentno = s.studentno
WHERE StudentResult IS NULL
-- Thinking questions : Query the information of the students who took the exam ( Student number , The student's name , Subject name , fraction )
SELECT s.studentno,studentname,subjectname,StudentResult
FROM student s
INNER JOIN result r
ON r.studentno = s.studentno
INNER JOIN `subject` sub
ON sub.subjectno = r.subjectno
边栏推荐
- 瑞萨RZ/G2L 处理器简介|框架图|功耗|原理图及硬件设计指南
- Mongodb common commands of mongodb series
- Infrared thermography temperature detection system based on arm rk3568
- Basic use of sringcloud & use of component Nacos
- 测试右移:线上质量监控 ELK 实战
- 有向图的强连通分量
- 异步、郵件、定時三大任務
- The difference between relational database and non relational database
- Excel calculates the difference between time and date and converts it into minutes
- Inversion de l'intervalle spécifié dans la liste des liens
猜你喜欢
leetcode:871. Minimum refueling times [Pat has done before + maximum stacking + greed]
Reading and writing speed of Reza rz/g2l arm development board storage and network measurement
[AUTOSAR twelve mode management]
[AUTOSAR I overview]
JS inheritance and prototype chain
瑞萨RZ/G2L 处理器简介|框架图|功耗|原理图及硬件设计指南
[love crash] neglected details of gibaro
【FPGA教程案例6】基于vivado核的双口RAM设计与实现
matlab 多普勒效应产生振动信号和处理
这不平凡的两年,感谢我们一直在一起!
随机推荐
Matlab Doppler effect produces vibration signal and processing
leetcode:871. 最低加油次数【以前pat做过 + 最大堆 +贪心】
Basic remote connection tool xshell
matlab将数字矩阵保存为地理空间数据出错,显示下标索引必须为正整数类型或逻辑类型,解决
异步、郵件、定時三大任務
Draw love with go+ to express love to her beloved
2022.2.14 resumption
机器学习术语
Cut point of undirected graph
1696C. Fishingprince Plays With Array【思维题 + 中间状态 + 优化存储】
Leetcode-2115: find all the dishes that can be made from the given raw materials
First hand evaluation of Reza electronics rz/g2l development board
excel去除小数点后面的数据,将数字取整
Deep analysis of data storage in memory
Specified interval inversion in the linked list
[AUTOSAR nine c/s principle Architecture]
Advanced pointer (I)
leetcode:871. Minimum refueling times [Pat has done before + maximum stacking + greed]
[flutter] icons component (load the built-in icon of flutter | display the material design icon completely)
Esp32 simple speed message test of ros2 (limit frequency)