+ 3
What is the difference between join and union?
4 Answers
+ 6
Join mix fields from multiple table following a specific condition, usually a relationship between a foreign and primary key.
Union combines result set of a query with those of another. The combined result sets must contain same amount of columns (fields) and each field in all the combined result sets must be of the same type for the union to work.
Hth, cmiiw
+ 4
join is getting multiple columns combining multiple tables based on condition.
union is getting multiple rows combining multiple tables, condition is both the tables have same column.
+ 2
I try giving a non technical example because Ipang and Mohammed already explained it with Tables and columns.
Think about two slices of paper (A and B). They may have a different format (width and length). Join is like taking vertical slices of sheet B (A or B depends on The use of left and right Join) and appending them to the side of the other.
UNION is taking a horizontal slice of B and appending it to the bottom of your other Sheet of paper. Please note that for a Union the sheets A and B have to be of the same width ( it would look strange glueing paper of different width together) the content should contain the same data and not Mix unrelated data together.
- 1
fecha BETWEEN '2018-12-01' AND '2018-12-18'
1,2,3...18-12-2018
JOIN is getting data table 1 and table 2 on condition
SELECTÂ table1.columnA, table2.columnA1
FROMÂ table
INNERÂ JOINÂ table on condition;