Monday, May 6, 2024

Union vs union all SQL server - Union SQL

Union will remove duplicates. Union All does not.

Note:- For union , must have same columns.

example

Union

Select top (select COUNT(*) from CourtApplicationDetails) * From CourtApplicationDetails

union 

Select top ((select COUNT(*) from CourtApplicationDetails)-(1)) * From CourtApplicationDetails

===============================

union all


Select top (select COUNT(*) from CourtApplicationDetails) * From CourtApplicationDetails

union all

Select top ((select COUNT(*) from CourtApplicationDetails)-(1)) * From CourtApplicationDetails

No comments:

Post a Comment