What is the difference between union and union all ?
Let us assume, i have two tables
Table 1
Table 2
Table 1 have the following records
1
2
3
4
5
Table 2 have the following records
5
6
7
8
9
10
Now fire the below query in SQL Assistant
Select * from table1
Union
Select * from table2
Now we will get below records..
1
2
3
4
5
6
7
8
9
10
So we come to know, when ever we use union key word, it fetches only unique records.
Select * from table1
Union all
Select * from table 2
We well get the below records
1
2
3
4
5
5
6
7
8
9
10
If you use union all keyword between two or more SQL statements, we will get the unique records as well as duplicates will fetches.
If any concern please drop a mail..
No comments:
Post a Comment