SQL SET OPERATIONS

DB2 SQL SET OPERATIONS : INTERSECT


SQL INTERSECT

SQL INTERSECT return records which are common in all the SELECT queries involved in operation. INTERSECT only return unique value, all duplicate values are removed from final result.
SELECT id1 FROM table1 INTERSECT SELECT id2 FROM table2


Here is how SQL INTERSECT 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 common records from
Query 1 and Query 2.
 

ID1
4
5
4
5
5
4. Remove Duplicated values.
 
 

ID1
4
5

IBM i developer.

View Comments
There are currently no comments.