-2

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?

Narasimha Maiya
  • 1,009
  • 4
  • 12
  • 35
  • 1
    Short answer, no. `JOIN` and `UNION` are different operations. – Felix Pamittan Jan 11 '16 at 07:08
  • UNION operator is just for combining two or more SELECT statements. While, JOIN is for select rows from each tables either Inner, Outer, Left or right method. you can refer http://stackoverflow.com/questions/905379/what-is-the-difference-between-join-and-union – bmsqldev Jan 11 '16 at 07:09
  • Why the SQL Server and Oracle tags? Don't tag products not involved... – jarlh Jan 11 '16 at 08:01

3 Answers3

2

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.

UNION

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.

JOIN

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.

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
1

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

iDevlop
  • 24,841
  • 11
  • 90
  • 149
  • For that comparison is necessary and as per my Knowledge without join comparing is not possible. So oracle Engine should use join. – Narasimha Maiya Jan 11 '16 at 07:25
0

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

enter image description here

Thank you for reply.

Jonnus
  • 2,988
  • 2
  • 24
  • 33
Narasimha Maiya
  • 1,009
  • 4
  • 12
  • 35