How Do I Create a Union in Mysql

MySQL UNION operator allows you to combine two or more result sets of queries into a single result set. The following illustrates the syntax of the UNION operator: SELECT column_list UNION [DISTINCT | ALL] SELECT column_list UNION [DISTINCT | ALL] SELECT column_list …

How do I create a union query in MySQL?

Example – Return single field SELECT supplier_id FROM suppliers UNION SELECT supplier_id FROM order_details; In this MySQL UNION operator example, if a supplier_id appeared in both the suppliers and order_details table, it would appear once in your result set. The MySQL UNION operator removes duplicates.

Does MySQL support union?

You can use UNION if you want to select rows one after the other from several tables or several sets of rows from a single table all as a single result set. UNION is available as of MySQL 4.0.

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest