From the course: SQL: Data Reporting and Analysis
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
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
-
-
-
-
-
-
(Locked)
Make your queries faster1m 47s
-
(Locked)
Understand SQL indexes and keys7m 16s
-
(Locked)
EDIT: Visualize your database7m 58s
-
(Locked)
Merge data across tables with JOIN5m 2s
-
(Locked)
Understand SQL JOINS4m 16s
-
(Locked)
Combine rows with SQL UNION4m 49s
-
(Locked)
Merge data across tables with IN2m 11s
-
(Locked)
Select from a selection with subqueries2m 56s
-
(Locked)
Challenge: Join tables1m 4s
-
(Locked)
Solution: Join tables4m 37s
-
(Locked)
-
-