SQL SET OPERATIONS

DB2 SQL SET OPERATIONS : EXCEPT


SQL EXCEPT

SQL EXCEPT returns records from first SELECT query which are not present in any other SELECT queries. EXCEPT only return unique value, all duplicate values are removed from final result.

SELECT id1 FROM table1 EXCEPT SELECT id2 FROM table2

Here is how SQL EXCEPT works [SAMPLE DATA]

1. Execute Query 1
“SELECT id1 FROM table1”
and get result set.

TABLE1.ID1
1
2
3
4
5
1
2
2. Execute Query 2
“SELECT id2 FROM table2”
and get result set.

TABLE2.ID2
4
5
6
7
8
5
6
3. Get Query 1 records
which are not in Query 2.
 

ID1
1
2
3
1
2
4. Remove Duplicated values.
 
 

ID1
1
2
3

IBM i developer.

View Comments
There are currently no comments.