less than 1 minute read

UNION removes duplicate records, whereas UNION ALL does not.

> SELECT 'foo' AS bar UNION SELECT 'foo' AS bar
+-----+
| bar |
+-----+
| foo |
+-----+
1 row in set (0.00 sec)

> SELECT 'foo' AS bar UNION ALL SELECT 'foo' AS bar
+-----+
| bar |
+-----+
| foo |
| foo |
+-----+
2 rows in set (0.00 sec)

Via SO.

Tags: ,

Categories:

Updated:

Leave a comment