Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Combining Results of two or more SELECT Statements

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 498
    Comment on it

    Combining Results of two or SELECT Statements using UNION OPERATOR:

    UNION Operator is used to combine the results of two or more SELECT statements. But UNION operator does not return duplicate rows so to return duplicate rows UNION ALL operator is used.

    Some important points while using UNION Operator:

    • All SELECT statement must have same number of columns to be fetched .
    • All SELECT statement columns to be fetched must have similar dataypes .

    Syntax for UNION operator:

    1. SELECT columnname(s)
    2. FROM tablename
    3. WHERE [condition]
    4. UNION
    5. SELECT columnname(s)
    6. FROM tablename
    7. WHERE [condition];

    Syntax for UNION ALL operator:

    1. SELECT columnname(s)
    2. FROM tablename
    3. WHERE [condition]
    4. UNION ALL
    5. SELECT columnname(s)
    6. FROM tablename
    7. WHERE [condition];

    Example:

    1. SELECT City FROM Employee
    2. UNION
    3. SELECT City FROM Trainee;

    The above query will fetch all different cities from Employee and Trainee tables.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: