当前位置:网站首页>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 .

边栏推荐
- Office提示系统配置无法运行怎么办?
- sql日志
- Improve the readability of your regular expressions a hundred times
- Numpy basic learning
- Deep learning brush a bunch of tricks of SOTA
- 怎样监测微型的网站服务
- 传奇如何一台服务器配置多个版本微端更新
- 传奇开区网站如何添加流量统计代码
- [wechat applet -- solve the alignment problem of the last line of display:flex. (discontinuous arrangement will be divided into two sides)]
- stack和queue和优先级队列(大堆和小堆)模拟实现和仿函数讲解
猜你喜欢

Opencv learning 1 (environment configuration)

The song of the virtual idol was originally generated in this way!

Jackson parsing JSON detailed tutorial

Mysql把查询到的结果集按指定顺寻进行排序

SparkSql批量插入或更新,保存数据到Mysql中

js(forEach)出现return无法结束函数的解决方法

Pytorch learning notes

网安学习-内网安全1

让你的正则表达式可读性提高一百倍

Young freshmen yearn for more open source | here comes the escape guide from open source to employment!
随机推荐
搭建手机APP需要用到什么服务器
How to set row height and column width in excel? The method of setting row height and column width in Excel
A little knowledge about management
【无标题】
开源汇智创未来 | 2022开放原子全球开源峰会 openEuler 分论坛圆满召开
【微信小程序--解决display:flex最后一行对齐问题。(不连续排列会分到两边)】
"Invisible Bridge" built in the free trade economy: domestic products and Chinese AI power
Force deduction ----- sort odd and even subscripts respectively
How to add traffic statistics codes to the legendary Development Zone website
Open source Huizhi creates the future | the openeuler sub forum of 2022 open atom global open source summit was successfully held
[wechat applet] swiper slides the page, and the left and right sides of the slider show part of the front and back, showing part of the front and back
TMUX essays
Solve the warning prompt of MySQL mapping file
Word如何查看文档修改痕迹?Word查看文档修改痕迹的方法
How does WPS use smart fill to quickly fill data? WPS method of quickly filling data
The difference between the two ways of thread implementation - simple summary
金达威董秘回复:公司看好NMN产品的市场前景,已推出系列产品
[untitled]
DataSourceClosedException: dataSource already closed at Mon Oct 25 16:55:48 CST 2021
如何让照片中的人物笑起来?HMS Core视频编辑服务一键微笑功能,让人物笑容更自然