It allow us to add one or more column from one or more table in a single output. It follow some conditions to perform they are:
SELECT columnname1, columnname2 FROM table1 UNION DISTINCT | ALL SELECT columnname1, columnname2 FROM table2 [WHERE CLAUSE ORDER BY CLAUSE]
SELECT ocuptn, sex FROM studptin UNION SELECT fname,age FROM studinfo ;
Default value use in union is distinct.
SELECT fname,age FROM studinfo UNION ALL SELECT ocuptn, sex FROM studptin ;
The full output can be shown by all in union condition.
SELECT ocuptn, sex FROM studptin UNION SELECT fname,age FROM studinfo WHERE age>23 ORDER BY ocuptn;
Include the where and order b y condition in the above code.
( SELECT ocuptn, sex FROM studptin ) UNION ( SELECT fname,age FROM studinfo ) ORDER BY 2,1;
The type of order define in terms of the second select column name define in the code.
(追記) (追記ここまで)Others
Languages
Frameworks
Web / Design
Mobile Technology
Sql & Technology
R4R