Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The difference between union and union all

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

[example]

First, create two tables An and B. in order to facilitate understanding, both tables create only one field column, namely a_col and b_col, and add Table A.

Data 1, 4, 5, 9, add table B data 2, 3, 4, 5.

Enter the following sentence: select * from A union select * from B

Results: 1,4,5,9,2,3. (duplicate lines removed)

Enter the following statement: select * from A union all select * from B

Results: 1,4,5,9,2,3,4,5. (duplicate lines are not removed)

[conclusion]

Union: joins two result sets, excluding duplicate rows, and sorts the default rules

Union All: joins two result sets, including duplicate rows, without sorting

[notes]

Using union and union all must ensure that the result of each select collection has the same number of columns, and that the type of each column is

The same, but the column names do not need to be the same.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report