当前位置:网站首页>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 .
边栏推荐
- [ten minutes] manim installation 2022
- 【论文阅读|深读】Role2Vec:Role-Based Graph Embeddings
- 1152_ Makefile learning_ Pattern matching rules
- 图的邻接矩阵存储 C语言实现BFS
- Utilisation de foreach en Qt
- Stc89c52/90c516rd/89c516rd ADC0832 ADC driver code
- 2021-07-05
- 【力扣刷题总结】数据库题目按知识点分类总结(持续更新/简单和中等题已完结)
- Using virtual environments in jupyter notebook
- [note] May 23, 2022 MySQL
猜你喜欢
![[QT] QMap使用详解](/img/ee/6e71a3dc5b90d2d1b7f7d3f6b56221.png)
[QT] QMap使用详解

共124篇!墨天轮“高可用架构”干货文档分享(含Oracle、MySQL、PG)

Implementation of property management system with ssm+ wechat applet

11: I came out at 11:04 after the interview. What I asked was really too

云原生——Web实时通信技术之Websocket

1150_ Makefile learning_ Duplicate name target processing in makefile

毕业设计EMS办公管理系统(B/S结构)+J2EE+SQLserver8.0

华为云原生——数据开发与DataFactory
![[punch in - Blue Bridge Cup] day 5 --- lower() small](/img/b5/21f51a7416c72c299cc59192a33b3a.jpg)
[punch in - Blue Bridge Cup] day 5 --- lower() small
![[note] May 23, 2022 MySQL](/img/a1/dd71610236729e1d25c4c3e903c0e0.png)
[note] May 23, 2022 MySQL
随机推荐
Global and Chinese market of medical mass notification system 2022-2028: Research Report on technology, participants, trends, market size and share
Hash design and memory saving data structure design in redis
Huawei interview question: divide candy
Global and Chinese markets for active transdermal drug delivery devices 2022-2028: Research Report on technology, participants, trends, market size and share
MySQL performance optimization (6): read write separation
华为云原生——数据开发与DataFactory
dbt产品初体验
December2020 - true questions and analysis of C language (Level 2) in the youth level examination of the Electronic Society
Global and Chinese market of ULTRACENTRIFUGES 2022-2028: Research Report on technology, participants, trends, market size and share
[wechat applet] how did the conditional rendering list render work?
你清楚AI、数据库与计算机体系
Note: load the configuration file as a byte stream and get the resources in it
(03).NET MAUI实战 基础控件
LitJson解析 生成json文件 读取json文件中的字典
Laravel9 installation locale
X Book 6.97 shield unidbg calling method
Chapter 2 control structure and function (programming problem)
[0x0] open questions left by the principal
将DataBinding整合到Activity/Fragment的一种极简方式
【十分钟】manim安装 2022