4
Reply

What is the differences between UNION & JOINS in sql server?

    A 'Union selects rows' and Join 'selects columns from 2 or more tables'.

    JOIN: A Join is used for displaying columns with the same or different names from different tables. The output displayed will have all the columns shown individually. i.e. The columns will be aligned next to each other. UNION: The UNION set operator is used for combining data from two tables which have columns with the same datatype. When a UNION is performed the data from both tables will be collected in a single column having the same datatype.

    A join selects columns from 2 or more tables. A union selects rows

    joins is used in our query
    like,
    SELECT column_name(s)
    FROM table_name1
    INNER JOIN table_name2
    ON table_name1.column_name=table_name2.column_name

    and union is used to merge the result of two query

    like,

    select * from table1
    union
    select * from table2