MySQL SQLLesson 35Free preview
MySQL UNION ALL
This lesson is part of MySQL · All levels
Summary
UNION ALL is used to combine the results of two or more SELECT queries into one final result. Unlike ordinary UNION, UNION ALL maintains all lines including duplicate ones so that the result is more complete and the process faster. Each query combined must have the same number of columns and corresponding data types.
Key points
- All Union displays all the lines of each query, duplicates still appear
- The unity without ALL automatically deletes the duplicate line so that the result can be less.
- The number and order of columns on each SELECT must match, the data type must also match
- The column name on the end result is taken from the first query
- Use ORDER BY only in the last query to sort all the combined results
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.