当前位置:网站首页>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
边栏推荐
- 【FH-GFSK】FH-GFSK信号分析与盲解调研究
- 链表中的节点每k个一组翻转
- R language ggplot2 visual faceting, visual facet_wrap bar plot, using strip Text function customize the size of the strip of each facet title in the facet graph (cutimi
- 瑞萨电子RZ/G2L开发板上手评测
- First hand evaluation of Reza electronics rz/g2l development board
- The arm core board / development board of Feiling equipped with Ti am62x made its debut in embedded world 2022
- 1038 Recover the Smallest Number
- Inversion de l'intervalle spécifié dans la liste des liens
- Merge K sorted linked lists
- matlab 多普勒效应产生振动信号和处理
猜你喜欢
[overview of AUTOSAR three RTE]
Matlab saves the digital matrix as geospatial data, and the display subscript index must be of positive integer type or logical type. Solve the problem
MySQL basic usage 02
[flutter] icons component (fluttericon Download Icon | customize SVG icon to generate TTF font file | use the downloaded TTF icon file)
JS inheritance and prototype chain
Advanced pointer (I)
用Go+绘制爱心给心爱的她表白
[AUTOSAR VI description document]
12_微信小程序之微信视频号滚动自动播放视频效果实现
The difference between tail -f, tail -f and tail
随机推荐
Meibeer company is called "Manhattan Project", and its product name is related to the atomic bomb, which has caused dissatisfaction among Japanese netizens
465. DFS backtracking of optimal bill balance
Esp32 simple speed message test of ros2 (limit frequency)
FPGA - 7 Series FPGA internal structure clocking -04- multi area clock
Test shift right: Elk practice of online quality monitoring
R language ggplot2 visual faceting, visual facet_wrap bar plot, using strip Text function customize the size of the strip of each facet title in the facet graph (cutimi
Deep analysis of data storage in memory
瑞萨RZ/G2L ARM开发板存储读写速度与网络实测
飞凌搭载TI AM62x的ARM核心板/开发板首发上市,亮相Embedded World 2022
The difference between tail -f, tail -f and tail
Thank you for being together for these extraordinary two years!
Explain the basic concepts and five attributes of RDD in detail
Rk3568 development board evaluation (II): development environment construction
Machine learning terminology
[C language] branch and loop statements (Part 1)
Data analysis, thinking, law breaking and professional knowledge -- analysis method (I)
基本远程连接工具Xshell
[love crash] neglected details of gibaro
[AUTOSAR VI description document]
1038 Recover the Smallest Number