In UNION
their will be no duplicate values so it will search other table entirely before considering a row.
dose it make UNION
as a kind of join?
In UNION
their will be no duplicate values so it will search other table entirely before considering a row.
dose it make UNION
as a kind of join?
dose it make UNION as a kind of join?
NO
UNION is used to combine the result of two queries. Whereas JOIN is used to get the data using a logical relationship between the tables.
Combines the results of two or more queries into a single result set that includes all the rows that belong to all queries in the union. The UNION operation is different from using joins that combine columns from two tables.
By using joins, you can retrieve data from two or more tables based on logical relationships between the tables. Joins indicate how Microsoft SQL Server should use data from one table to select the rows in another table.
To make VERY simple:
- with JOIN you put 2 datasets - generally with different columns, "side by side",
- with UNION you put 2 datasets - with identical columns - one above the other
Sorry I asked question too soon. i.e without trying everything.
I misunderstood the working of UNION
so I created a plan for union and found that before UNION
UNION ALL
will execute and from the result set we are extracting unique set of data.
explain plan for
select * from table_a
union
select * from table_b
plan output came like this
Thank you for reply.