Union is a set operator that can be used to combine the result set of two different SELECT statement. In the union number of columns and data type should be the same.
It has two types −
On the other hand ,In a Relational database, tables are associated with each other and we used foreign key to maintain relationships between tables. We used join clause to retrieve data from associated tables. The join condition indicates how column in each table are matched against each other.
There are two types of joins clause in SQL
It can be used to retrieve matched records between both tables or more tables
It can be used to combine the result set of two different SELECT statement.
Result set can have different types of data types
Data type should be same as the result set of each select statement
It doesn't remove duplicate data.
It removes duplicate rows between the various select statements.
SELECT columnlist FROM tableA UNION SELECT columnlist FROM tableB
SELECT columnlist FROM TableA INNER JOIN TableB ON join condition