What Are The Differences Between JOINS And UNIONS In Oracle?

4

4 Answers

Anonymous Profile
Anonymous answered
This question most people ask. I think the only reason people are confused is because both these operators are used to combine two or more set of rows. But of both of them a very different concepts and are used under different circumstances. They are definitely not equivalent. Now what is the difference?
A joins is usually used to combine rows from multiple tables. There are different types of joins, such as inner and outer joins. Inner joins return all the rows from multiple tables on which the condition is set whereas outer join returns all rows from one table and only those rows from a secondary table where the join condition is met.
Now coming to union. It is a set operator. Suppose you have
Col1
A
Col2
B

Col1 union Col2 returns
A
B

The difference between them is when to use.
A join is used when we want to filter rows on the basis of (Cross Multiplication/Subtraction/Minus etc) and the tables on which union is applied has different or same number of columns.
Union is basically used to merge two or more sets with number/type/name of column. It should be noted that the union operator can only be applied when number and data types of the columns in the two tables are the same.
Anonymous Profile
Anonymous answered
I think if we want to retrieve data from two tables based on the condition then join is a better option.Otherwise we can use set operations to simply combine  sets of data from different tables.Moreover, queries that contain join take more time that set operations to operate.
If you have other differences please reply.
Anonymous Profile
Anonymous answered
The common thing in both union and join is that both are used to combine data from more than one table or more than one row. But there is a big difference between them.
WE use join operator when we want to combine data by using any condition. For example I want to combine data from two tables and the condition is that all those employees who have salary less than 2000 will not be included. Then I can apply join operation because I want to combine data from two different tables using a condition which is all employees must have salary less than 2000.

Union is also used to combine data from more than one table but it has duplicate values and it can be applied only when both tables have same data types. For example I want to combine data from EMP table and supervisor table and if both tables have same data type then I can apply union operation but if data types are different then it is not possible. Union command is not used with a condition.
Anonymous Profile
Anonymous answered
Joins explanation and difference

Answer Question

Anonymous