Multiple select query with where condition

    combining two select statements in sql query
    join two select statements in sql server
    can you use multiple select statements in sql
    can you have multiple select statements in sql
  • Combining two select statements in sql query
  • How to combine two sql queries in one result without union...

    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

      can you have 2 select statements in sql
      combine two select statements with different columns