Sql union

    use multiple select statements in sql
    create view with multiple select statements in sql
    insert query with multiple select statements in sql
    how to use two select statements in sql stored procedure
  • Use multiple select statements in sql
  • Multiple select statements in one query!

    Problem

    You’d like to display data from given columns (of a similar data type) from two tables in SQL.

    Example

    There are two tables in our database: and .

    The table contains data in the following columns: , , , and .

    idfirst_namelast_nameage
    1TomMiller22
    2JohnSmith26
    3LisaWilliams30
    4CharlesDavis21
    5JamesMoore22

    The table contains data in the following columns: , , , and .

    idfirst_namelast_nameage
    1MilanSmith45
    2CharlesDavis21
    3MarkBacker19

    In one result set, let’s display the first name, last name, and age for all people in the database, both employees and customers.

    Solution 1

    We’ll use to combine data from columns in two tables.

    Here’s the query you’d write:

    SELECT first_name, last_name, age FROM employee UNION ALL SELECT first_name, last_name, age FROM customer;

    Here’s the result:

    first_namelast_nameage
    TomMiller22
    JohnSmith26
    LisaWilliams30
    CharlesDavis21
    JamesMoore28
    MilanSmith45
    CharlesDavis21
    MarkBa

      multiple select statements in sql stored procedure
      join multiple select statements in sql