当前位置:网站首页>Self join and joint query of MySQL
Self join and joint query of MySQL
2022-07-29 05:11:00 【nianyuw】
Self join
Self connect query
Self connect query , seeing the name of a thing one thinks of its function , Is to connect yourself , That is to connect and query a table many times . For self join queries , It can be internal connection query , It can also be an external connection query .
Note that the self connection must be aliased
SELECT Field list FROM surface A Alias A JOIN surface A Alias B ON Conditions ... ;
Query the names of employees and their leaders
select a.name , b.name from emp a , emp b where a.managerid = b.id;
The joint query
about union Inquire about , Is to combine the results of multiple queries , Form a new query result set .
It can be used to query multiple unrelated table data at one time
The number of columns in multiple tables of joint query must be consistent , Field types also need to be consistent .
union all All the data will be merged directly ,union The merged data will be de duplicated
SELECT Field list FROM surface A ...
UNION [ ALL ]
SELECT Field list FROM surface B ....;
Lower salary than 5000 The employees' , and Older than 50 All the employees aged 18 are found out
select * from emp where salary < 5000
union all
select * from emp where age > 50;
union all The result of the search , Simply merge , No weight loss .
select * from emp where salary < 5000
union
select * from emp where age > 50;
union The joint query , The query results will be de reprocessed .
边栏推荐
- Jackson parsing JSON detailed tutorial
- Climbing the pit of traffic flow prediction (II): the simplest LSTM predicts traffic flow using tensorflow2
- Mysql语句中的函数
- MySQL定时调用预置函数完成数据更新
- Sparksql inserts or updates in batches and saves data to MySQL
- 1 sentence of code, get asp Net core binds multiple sources to the same class
- Use openmap and ArcGIS to draw maps and transportation networks of any region, and convert OMS data into SHP format
- Stack and queue and priority queue (large heap and small heap) simulation implementation and explanation of imitation function
- 向往的开源之多YOUNG新生 | 从开源到就业的避坑指南来啦!
- 【2022新生学习】第三周要点
猜你喜欢
ODOO开发教程之图表
How to install Office2010 installation package? How to install Office2010 installation package on computer
MySQL regularly calls preset functions to complete data update
关于servlet中实现网站的页面跳转
[2022 freshmen learning] key points of the third week
【微信小程序--解决display:flex最后一行对齐问题。(不连续排列会分到两边)】
The representation of time series analysis: is the era of learning coming?
Improve the readability of your regular expressions a hundred times
[untitled]
Sparksql inserts or updates in batches and saves data to MySQL
随机推荐
[sudden] solve remote: support for password authentication was removed on August 13, 2021. please use a perso
关于thymeleaf的配置与使用
Mysql把查询到的结果集按指定顺寻进行排序
Use annotation test in idea
力扣------对奇偶下标分别排序
roLabelImg转DATO格式数据
ODOO开发教程之透视表
What servers are needed to build mobile app
office2010每次打开都要配置进度怎么解决?
Torch.nn.crossentropyloss() details
JS daily question (12)
WPS insert hyperlink cannot be opened. What should I do if I prompt "unable to open the specified file"!
How to open IE browser by running win command
Deadlock analysis using jstack, jconsole, and jvisualvm
AttributeError: ‘module‘ object has no attribute ‘create_connection‘
玩家访问网站自动弹窗加QQ群方法以及详细代码
Jackson解析JSON详细教程
Double type nullpointexception in Flink flow calculation
Introduction of JDBC preparestatement+ database connection pool
The most comprehensive promotion plan for the launch of new products