• SQL UNION CLAUSE AND UNION ALL CLAUSE – SQL TUTORIAL

    SQL UNION Clause:

    SQL UNION operator combines the result of two or more SELECT statements.

    The SQL UNION operator selects only distinct values by default.

    Syntax:

    Example:

    In the below image, you could find two three SQL statements. First two statements returns the records from tables PLAYERS and SCOREBOARD individually. In the third query, we have used UNION clause with the first two queries. UNION clause combines the first two queries and returns only the distinct values. In the result you could see only the values which are not duplicated.

    SQL Union Clause

    SQL UNION ALL Clause :

    SQL UNION operator combines the result of two or more SELECT statements. If we want to include the duplicate values too then we could use UNION ALL operator.

    Syntax:

    Example:

    In the below image, you could find two three SQL statements. First two statements returns the records from tables PLAYERS and SCOREBOARD individually. In the third query, we have used UNION ALL clause with the first two queries. UNION ALL clause combines the first two queries and returns the values from both the tables which includes duplicate values too (if any).

    SQL Union All

    In the next tutorial, we will see ORDER BY keyword in SQL

    Check out the complete SQL Tutorial by clicking on below link:

    SQL Tutorial – Complete

    Sharing is caring.

    Share on facebook
    Facebook
    Share on twitter
    Twitter
    Share on linkedin
    LinkedIn

    Like This Post?

    We have a lot more where that came from?

    We only send really good stuff occasionally, promise.

    Rajkumar SM

    Leave a Comment

    Your email address will not be published. Required fields are marked *

    Share on facebook
    Share on google
    Share on twitter
    Share on linkedin
    Share on whatsapp

    Recent Posts:

    Scroll to Top
    API Testing eBook

    DOWNLOAD FOR FREE