From the course: SQL: Data Reporting and Analysis

Unlock the full course today

Join today to access over 23,400 courses taught by industry experts.

Combine rows with SQL UNION

Combine rows with SQL UNION - SQL Tutorial

From the course: SQL: Data Reporting and Analysis

Combine rows with SQL UNION

- [Instructor] In previous sections, we've learned how to merge tables with a join. Joins allow us to merge columns from different tables. It's like a sort of horizontal merge. So if we start off with two tables of three columns and six rows, as we show in the diagram and we use a join, we would expect to output one table of six columns and six rows, assuming that there was a perfect match in each table for records in the other table. Unions are also a way of merging tables, but they work vertically instead of horizontally, and they don't care about matching records. So in this case where we have the same two input tables which are three columns and six rows, a union would output three columns, but 12 rows. So let's have a look at this query. Here we have a query that says, select the text address which is there in single quotes, as column name table. You can see the column name here, table. And then the date…

Contents