UNION UNION ALL

suggest change

Introduction

The UNION keyword combines two SELECT results and removes duplicate rows.

Both SELECT statements need the same number of columns, in the same order, with compatible types. Column lengths may differ.

Syntax

UNION | UNION ALL

SELECT column_1 [, column_2 ] FROM table_1 [, table_2 ] [WHERE condition]

Remarks

UNION and UNION ALL clauses combine the result-set of two or more identically structured SELECT statements into a single result / table.

Both the column count and column types for each query have to match in order for a UNION / UNION ALL to work.

The difference between a UNION and a UNION ALL query is that the UNION clause will remove any duplicate rows in the result where the UNION ALL will not.

Removing those duplicates can slow a query even when no duplicate rows exist. If you know there won't be duplicates, or you do not care, use UNION ALL.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents