当前位置:网站首页>Database learning – select (multi table joint query) [easy to understand]
Database learning – select (multi table joint query) [easy to understand]
2022-07-24 15:30:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
Multi table joint query
Joint query of multiple tables can be realized through join operation , The connection operation can be realized through the selection operation after the generalized Cartesian product .
Select Multi table joint query statement
Select Name [[, Name ]…] from Table name 1, Table name 2,,… Where Query criteria ;
have access to as Is a table or field ( attribute ) Take the alias ;
Select Name [[, Name ]…] from Table name 1 [as] Alias 1, Table name 2 [as} Alias 2,,… Where Query criteria ;
Select Name 1 [as] Column alias 1 [[, Name 2 [as] Column alias 2]…] from Table name 1 [as] Table alias 1, Table name 2 [as] Table alias 2,,… Where Query criteria ;
“[]” Indicates that the contents can be omitted ;
Query conditions should include connection conditions , Equivalent connection can be realized through different connection conditions 、 Unequal value connection and other connections .
Example :
The original table data :
Student list student
The teacher table teacher:
The curriculum course:
Course selection table student_course:
1 Press “0001” The student ID of all students will be displayed in order from high to low 、 full name 、 achievement ( Two meter connection );
SELECT
student.student_id,
student.student_name,
student_course.score
FROM
student,
student_course
WHERE
student.student_id = student_course.student_id
AND student_course.course_id = '0001'
ORDER BY
student_course.score DESC;When two ( Multiple ) There are the same fields in the table ( attribute , Name ) when , Use the table name ( Or table alias ). The form of column name distinguishes the query content from the condition content .
Running results :
2 Press “ Advanced mathematics ” The names of all students are displayed in order of course grades 、 Student number 、 fraction 、 Course name ( Three meter connection );
SELECT
st.student_id,
st.student_name,
sc.score,
co.course_name
FROM
student AS st,
student_course AS sc,
course AS co
WHERE
st.student_id = sc.student_id
AND sc.course_id = co.course_id
AND co.course_name = ' Advanced mathematics '
ORDER BY
sc.score DESC;Running results :
3 Query any two teachers with salary differences ( Single table connection query );
SELECT
t1.teacher_id AS ' Faculty number 1',
t1.teacher_name AS ' Teacher's name 1',
t2.teacher_id AS ' Faculty number 2',
t2.teacher_name AS ' Teacher's name 2'
FROM
teacher t1,
teacher t2
WHERE
t1.teacher_salary > t2.teacher_salary;Running results :
( More data , Only a part is shown here )
4 Query has been learned “0001” I've learned “0002” Student numbers of all students in course No ;
SELECT
sc1.student_id ' Student number '
FROM
student_course sc1,
student_course sc2
WHERE
sc1.student_id = sc2.student_id
AND sc1.course_id = '0001'
AND sc2.course_id = '0002';Running results :
5 Inquire about “0001” Course No “0002” Student ID names of all students with low grades in course No ;
SELECT
st.student_id ' Student number ',
st.student_name ' full name '
FROM
student_course sc1,
student_course sc2,
student st
WHERE
sc1.student_id = sc2.student_id
AND sc1.student_id = st.student_id
AND sc1.course_id = '0001'
AND sc2.course_id = '0002'
AND sc1.score < sc2.score;Running results :
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/124750.html Link to the original text :https://javaforall.cn
边栏推荐
- Discussion and legitimacy of the order of entering and leaving the stack
- The accuracy of yolov7 in cracking down on counterfeits, not all papers are authentic
- 【洛谷】P1908 逆序对
- 2022 robocom world robot developer competition - undergraduate group (provincial competition) -- question 2: intelligent medication assistant (finished)
- 【Flutter -- 布局】流式布局(Flow和Wrap)
- 在哪家证券公司开户最好最安全 如何开户炒股票
- 2022 RoboCom 世界机器人开发者大赛-本科组(省赛)-- 第二题 智能服药助手 (已完结)
- [USENIX atc'22] an efficient distributed training framework whale that supports the super large-scale model of heterogeneous GPU clusters
- Error reporting [project error reporting]
- 文件操作详解
猜你喜欢

JUC源码学习笔记3——AQS等待队列和CyclicBarrier,BlockingQueue

JMeter - call the interface for uploading files or pictures

26. Code implementation of file using disk

24.原生磁盘的使用

2022 RoboCom 世界机器人开发者大赛-本科组(省赛)-- 第三题 跑团机器人 (已完结)

Kubectl_ Easy to use command line tool: Oh my Zsh_ Tips and tricks
![Error reporting [project error reporting]](/img/7a/322ba86c13667a62c484b2329ac617.png)
Error reporting [project error reporting]

Unity uses NVIDIA flex for unity plug-in to realize the effects of making software, water, fluid, cloth, etc. learning tutorial

2022 RoboCom 世界机器人开发者大赛-本科组(省赛)RC-u4 攻略分队 (已完结)

(09) flask is OK if it has hands - cookies and sessions
随机推荐
Nine key measures to maintain server security in Hong Kong
Android section 13 detailed explanation of 03sqlite database
C# 无操作则退出登陆
Multus of kubernetes multi network card scheme_ CNI deployment and basic use
Route planning method for UAV in unknown environment based on improved SAS algorithm
4279. 笛卡尔树
What is a firewall? What role can firewalls play?
Conflict resolution of onblur and onchange
25.从生磁盘到文件
MySql函数
How to deal with being attacked? Advanced anti DDoS IP protection strategy
在哪家证券公司开户最好最安全 如何开户炒股票
Sklearn.metrics module model evaluation function
接参处理和@Param
Wildfire STM32 domineering, through the firmware library to achieve water light
C. Recover an RBS
【机器学习基础】——另一个视角解释SVM
Analysis of some difficulties in VAE (variational self encoder)
DS diagram - the shortest path of the diagram (excluding the code framework)
(09) flask is OK if it has hands - cookies and sessions