当前位置:网站首页>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
边栏推荐
- [AUTOSAR XIII NVM]
- Explain the basic concepts and five attributes of RDD in detail
- Key wizard hit strange learning - automatic path finding back to hit strange points
- Telephone network problems
- Rk3568 development board evaluation (II): development environment construction
- 无向图的割点
- Asynchronous, email and scheduled tasks
- The R language uses the ctree function in the party package to build conditional inference decision trees, uses the plot function to visualize the trained conditional inference decision tree, and the
- MySQL
- Leetcode-224: basic calculator
猜你喜欢
随机推荐
465. 最优账单平衡 DFS 回溯
Key wizard hit strange learning - automatic path finding back to hit strange points
R language generalized linear model function GLM, (model fit and expression diagnostics), model adequacy evaluation method, use plot function and car package function
Explain the basic concepts and five attributes of RDD in detail
matlab查找某一行或者某一列在矩阵中的位置
Advanced pointer (I)
Embrace the safety concept of platform delivery
这不平凡的两年,感谢我们一直在一起!
MySQL基础用法02
[shutter] image component (cached_network_image network image caching plug-in)
[AUTOSAR eight OS]
按键精灵打怪学习-多线程后台坐标识别
[AUTOSAR twelve mode management]
First hand evaluation of Reza electronics rz/g2l development board
Excel calculates the difference between time and date and converts it into minutes
合并K个已排序的链表
[自我管理]时间、精力与习惯管理
[case sharing] let the development of education in the new era advance with "number"
异步、邮件、定时三大任务
Specified interval inversion in the linked list








![[overview of AUTOSAR four BSW]](/img/19/c2273bbedb7f8d859e5a3805ed5740.png)
