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-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

The similarities and differences between union and union all

Similarities:

Both union and union all operate on the union of multiple query results

Differences:

1.union will not output duplicate rows with two results union.

2.union all will output duplicate rows with two results joined.

Experimental table

Field explanation:

Xh: student number

Xh: first name

Nl: age

Create table student (xh number,xm varchar2 (4), nl int); insert into student values (1); insert into student values (2); insert into student values (3); insert into student values (4); insert into student values (5); insert into student values (6); insert into student values (7)

View tabl

SQL > select * from student; XH XM NL- 1 A 21 2 B 21 3 A 21 4 A 21 5 A 21 6 C 217 B 217 rows selected.SQL > example

Union

SQL > select * from student 2 union 3 select * from student where xm='A' XH XM NL- 1 A 21 2 B 21 3 A 21 4 A 21 5 A 21 6 C 217 B 217 rows selected.SQL >

Union all

SQL > select * from student 2 union all 3 select * from student where xm='A' XH XM NL- 1 A 21 2 B 21 3 A 21 4 A 21 5 A 21 6 C 21 7 B 21 1 A 21 3 A 21 4 A 21 5 A 2111 rows selected.SQL >

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