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.
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.