当前位置:网站首页>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 .
边栏推荐
- 云原生入门+容器概念介绍
- 1152_ Makefile learning_ Pattern matching rules
- UML diagrams and list collections
- 【笔记】2022.5.28 从网页获取数据并写入数据库
- 51 single chip microcomputer indoor environment monitoring system, mq-2 smoke sensor and DHT11 temperature and humidity sensor, schematic diagram, C programming and simulation
- From 2500 a month, no one wants to go to the programming road of the technical director of a large factory | my ten years
- Integrating viewbinding and viewholder with reflection
- [personal summary] learning plan
- Product thinking - is the future of UAV express worth looking forward to?
- What are the defaults for Binding. Mode=Default for WPF controls?
猜你喜欢
![C # [advanced part] C # multithreading](/img/16/2a7c477b4cee32d9ce1e543c9d4c7e.png)
C # [advanced part] C # multithreading
![[punch in - Blue Bridge Cup] day 3 --- slice in reverse order list[: -1]](/img/c2/13693dcb51aab565957b6c5e686b7c.jpg)
[punch in - Blue Bridge Cup] day 3 --- slice in reverse order list[: -1]

【云原生】AI云开发平台——AI Model Foundry介绍(开发者可免费体验AI训练模型)

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

图的邻接矩阵存储 C语言实现BFS

Hash design and memory saving data structure design in redis

Half a year after joining the company, I was promoted to a management post

ThingsBoard教程(二三):在规则链中计算二个设备的温度差

dotnet-exec 0.5.0 released

C#【高级篇】 C# 多线程
随机推荐
Principle of device driver
Use common fileUpload to upload files
毕业设计EMS办公管理系统(B/S结构)+J2EE+SQLserver8.0
【个人总结】学习计划
[frequently asked questions] modularization of browser environment and node environment
51单片机的室内环境监测系统,MQ-2烟雾传感器和DHT11温湿度传感器,原理图,C编程和仿真
4-4 beauty ranking (10 points)
Buffer pool of MySQL notes
【云原生】AI云开发平台——AI Model Foundry介绍(开发者可免费体验AI训练模型)
【作业】2022.5.24 MySQL 查操作
What are the defaults for Binding. Mode=Default for WPF controls?
(03).NET MAUI实战 基础控件
[FAQ] page cross domain and interface Cross Domain
Mathematical solution of Joseph Ring
Use of foreach in QT
【笔记】2022.5.23 MySQL
Is the largest layoff and salary cut on the internet coming?
Global and Chinese market of centrifugal pumps 2022-2028: Research Report on technology, participants, trends, market size and share
将DataBinding整合到Activity/Fragment的一种极简方式
深入浅出掌握grpc通信框架