SELECT UNION Syntax

Updated on 2022-09-16 GMT+08:00

Common Syntax

SELECT ...UNION [ALL | DISTINCT] 
SELECT ...[UNION [ALL | DISTINCT] SELECT ...]

Example

select userid from user union select orderid from ordertbl order by userid;
select userid from user union (select orderid from ordertbl group by orderid) order by userid;

Syntax Restrictions

SELECT statements in UNION do not support duplicate column names.

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback