Answer» To combine data from two or more tables, you may use joins and UNIONS in your queries. Join: Essentially, joins allow you to combine data into new columns horizontally. A join clause is an SQL command used in order to combine records from multiple tables or retrieve data from these tables based on the existence of a common field (column) between them. In JOIN, the columns of the joining tables may differ. Here is a visual representation of how a join looks. See how the columns from Tables A and B have been combined to generate the result.
Union: In SQL, the term UNION is used to combine the results of more than one SELECT statement. Union allows you to combine data into new rows vertically. UNION requires that all queries have the same number of columns and order of columns. Here is a visual representation of how a union looks. See how the columns from Tables A and B have been combined to generate the result.
|