What is the difference between UNION and UNION ALL?

PointUNIONUNION ALL
DuplicatesRemovedKept
SpeedSlower (has to find duplicates)Faster
SELECT city FROM students
UNION
SELECT city FROM students;       -- 4 rows

SELECT city FROM students
UNION ALL
SELECT city FROM students;       -- 12 rows

Both queries must have the same number of columns. See MySQL UNION.


Learn more about the similar topics:
Tutorials
MySQL JOINs
MySQL Subqueries
MySQL UNION
Exercises & Assignments
Write a query to show the student name who has the second highest marks
Write a query to show the names of students with their course names
Write a query to count the students of each course, including empty courses
Write a query to find the students who scored above the average marks
Interview Questions & Answers
What is the difference between INNER JOIN and LEFT JOIN?
What is the difference between UNION and UNION ALL?
What are the types of JOINs in MySQL?
How to find the second highest marks in MySQL?
What is a subquery in MySQL?