当前位置:网站首页>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
边栏推荐
- Key wizard hit strange learning - automatic path finding back to hit strange points
- Leetcode-2115: find all the dishes that can be made from the given raw materials
- On Fibonacci sequence
- 比较版本号
- leetcode:701. Insertion in binary search tree [BST insertion]
- leetcode:871. 最低加油次数【以前pat做过 + 最大堆 +贪心】
- 【爱死机】《吉巴罗》被忽略的细节
- Find a benchmark comrade in arms | a million level real-time data platform, which can be used for free for life
- Data analysis, thinking, law breaking and professional knowledge -- analysis method (I)
- tail -f 、tail -F、tailf的区别
猜你喜欢

FPGA - 7系列 FPGA内部结构之Clocking -04- 多区域时钟
![[love crash] neglected details of gibaro](/img/d6/baa4b5185ddaf88f3df71a94a87ee2.jpg)
[love crash] neglected details of gibaro

leetcode:701. 二叉搜索树中的插入操作【bst的插入】
![[flutter] icons component (load the built-in icon of flutter | display the material design icon completely)](/img/f5/3ec22f1480227f33a1c8ac457155ed.jpg)
[flutter] icons component (load the built-in icon of flutter | display the material design icon completely)

FPGA - 7 Series FPGA internal structure clocking -04- multi area clock

Leetcode-849: maximum distance to the nearest person

Find a benchmark comrade in arms | a million level real-time data platform, which can be used for free for life

Strongly connected components of digraph

Daily topic: movement of haystack

全志A40i/T3如何通过SPI转CAN
随机推荐
Explain the basic concepts and five attributes of RDD in detail
R language ggplot2 visualization: use ggplot2 to display dataframe data that are all classified variables in the form of thermal diagram, and customize the legend color legend of factor
按键精灵打怪学习-自动寻路回打怪点
matlab查找某一行或者某一列在矩阵中的位置
拥抱平台化交付的安全理念
leetcode:871. 最低加油次数【以前pat做过 + 最大堆 +贪心】
Key detection and sinusoidal signal output developed by Arduino
Deep analysis of data storage in memory
[introduction to AUTOSAR seven tool chain]
Solve the cache problem of reactnative using WebView
[shutter] image component (configure local GIF image resources | load placeholder with local resources)
Kivy教程大全之如何在 Kivy 中创建下拉列表
1038 Recover the Smallest Number
电话网络问题
Leetcode-871: minimum refueling times
基本远程连接工具Xshell
RK3568开发板评测篇(二):开发环境搭建
[AUTOSAR 11 communication related mechanism]
[AUTOSAR XIII NVM]
Find a benchmark comrade in arms | a million level real-time data platform, which can be used for free for life