- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference between UNION and UNION ALL in DB2
The UNION in DB2 is used to merge two or more SELECT statements. The SELECT statements can be on a single table or on multiple tables. Each SELECT statement is processed individually and their results are combined to give us the final result rows.
The UNION statement will eliminate the duplicate rows appearing as a result of SELECT statements. If we want to retain the duplicate rows, then we can use the UNION ALL statement.
For example, if we want to extract all ORDER_ID with ORDER_TOTAL greater than 1000 in ORDERS and ORDERS_HIST table, we can use the below query with a UNION statement.
Example
SELECT ORDER_ID FROM ORDERS WHERE ORDER_TOTAL > 1000 UNION SELECT ORDER_ID FROM ORDERS_HIST WHERE ORDER_TOTAL > 1000
- Related Articles
- Difference Between Structure and Union
- Difference between Structure and Union in C
- Difference between Join and union in SQL
- Difference between Structure and Union in C Program
- What is the difference between DB2 JOIN and UNION? Explain with the help of an example
- State the difference between structure and union with suitable example in C language
- How to generate data with Union ALL and Insert ALL in Oracle?
- Union in C
- Anonymous Union and Structure in C
- Union() function in Python
- Union Method in C#
- Soviet Union (USSR)
- Explain Union process in DFA
- Union Type in PHP 8
- C# Queryable Union Method

Advertisements