What is the difference between UNION and UNION ALL?
What is the difference between UNION and UNION ALL ?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
UNIONremoves duplicate rows (where all columns in the results are the same),UNION ALLdoes not.There is a performance hit when using
UNIONinstead ofUNION ALL, since the database server must do additional work to remove the duplicate rows, but usually you do not want the duplicates (especially when developing reports).To identify duplicates, rows must be comparable types as well as compatible types. This will depend on the SQL system. For example the system may truncate all long text columns to make short text columns for comparison (MS Jet), or may refuse to compare binary columns (ORACLE)
UNION Example:
Result:
UNION ALL example:
Result: