当前位置:网站首页>Magical Union
Magical Union
2022-06-30 03:41:00 【smallfish118】
- This keyword cannot be said to have not been used , But it is only to query the same data , When different filtering conditions are required , Use union all Splice and then output together to view
- 8 month 24 Nikkei friends recommend an interview ( Hang up ), Asked about the use of the keyword , I'm confused , So I came down to study , It is found that this keyword can really be used in practical work
describe
UNION Operators are used to connect more than two SELECT The results of a statement are combined into a set of results . That is to find the union of multiple query results .
union yes union distinct Abbreviation , It has the function of weight removal , And the default will be based on ASCII Sort .union all Don't deal with it .
Example
select product.hospital_id,1 tables,null field1,product.product_type
from db_product.tb_discount_product product
where product.spu_id = 258933
union all
select cart.pid,2,cart.status,null
from db_order.`tb_shopping_cart` cart
where cart.id = 174
order by tables desc;Be careful
Same number of fields
Spliced multiple select The number of fields queried in the statement must be the same , As in my example above , Two select The number of fields queried in the statement is four , If it's not the same , The execution will report an error
Field names begin with the first select The query field shall prevail
As the example above , The fields of the query result are hospital_id,tables,field1,product_type These four fields .
Application scenarios
Multiple query results , Some fields have the same meaning , Want to splice together to see . This is the main requirement .
Pain points
But again, we may need to look at some other fields , However, these fields may only be included in one query and not in the other query .
union Provides a solution to this problem , Allow users to add query Columns . As the example shows tables Column 、field1 Column sum product_type Column .tables Column is used to distinguish which query statement the data comes from ;field1 The column in the first query does not , Only include... In the second query , A default value can be given in the first query null, In the second query, the specific value is queried ;product_type Then in field1 contrary .
边栏推荐
- Local, locallow and roaming in the appdata folder
- Global and Chinese market of bronze valves 2022-2028: Research Report on technology, participants, trends, market size and share
- laravel9本地安裝
- Hash design and memory saving data structure design in redis
- 1151_ Makefile learning_ Static matching pattern rules in makefile
- 124 articles in total! Motianlun "high availability architecture" dry goods document sharing (including Oracle, mysql, PG)
- UML diagrams and list collections
- On the optimization and use of idea
- 【作业】2022.5.25 MySQL 查操作2
- 2021-07-05
猜你喜欢

Hudi record

124 articles in total! Motianlun "high availability architecture" dry goods document sharing (including Oracle, mysql, PG)

December2020 - true questions and analysis of C language (Level 2) in the youth level examination of the Electronic Society

(03).NET MAUI实战 基础控件

QT中foreach的使用

Redis高并发分布式锁(学习总结)

第2章 控制结构和函数(编程题)

dotnet-exec 0.5.0 released

Number of students from junior college to Senior College (III)
![[wechat applet] how did the conditional rendering list render work?](/img/db/4e79279272b75759cdc8d6f31950f1.png)
[wechat applet] how did the conditional rendering list render work?
随机推荐
关于智能视觉组上的机械臂
Linked list: insert a node in the head
C#【高级篇】 C# 匿名方法【待补充Lambda表达式。。。】
【笔记】2022.5.27 通过pycharm操作MySQL
你清楚AI、数据库与计算机体系
[punch in - Blue Bridge Cup] day 2 --- format output format, ASCII
Usage record of unity input system (instance version)
[operation] getting started with MySQL on May 23, 2022
Redis high concurrency distributed locks (learning summary)
Buffer pool of MySQL notes
MySQL performance optimization (6): read write separation
Number of students from junior college to Senior College (4)
云原生——Web实时通信技术之Websocket
Product thinking - is the future of UAV express worth looking forward to?
【作业】2022.5.28 将CSV写入数据库
图的邻接矩阵存储 C语言实现BFS
Tidb 6.0: rendre les GRT plus efficaces 丨 tidb Book Rush
数据库的下一个变革方向——云原生数据库
Huawei interview question: divide candy
laravel9本地安裝