Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • SQL : Difference between UNION and UNION ALL

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 167
    Comment on it

    Both UNION and UNION ALL operators are used to combine the results of two or more SELECT statements. However the two differ as below:

    1) UNION performs a DISTINCT on the result set, removing any duplicate rows.There is a performance hit when using UNION since there is an additional effort of removing duplicates.

    Below is the syntax for using UNION.

    SELECT * FROM Table1 
       UNION
       SELECT * FROM Table2

    2) UNION ALL does not remove duplicates hence it faster than UNION.

    Below is the syntax for using UNION ALL.

    SELECT * FROM Table1
       UNION All
       SELECT * FROM Table2

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: