MySQL query to get result from multiple select statements?



To get result from multiple select statements, use UNION ALL. Following is the syntax −

select yourValue1 AS anyColumnName UNION ALL select yourValue2 AS yourColumnName . . . . N

Let us implement the above syntax in order to return enumeration of numbers in different rows −

mysql> select 100 AS Number    UNION ALL    select 1000 AS Number    UNION ALL    select 10000 AS Number    UNION ALL    select 100000 AS Number    UNION ALL    select 1000000 AS Number    UNION ALL    select 10000000 AS Number    UNION ALL    select 100000000 AS Number    UNION ALL    select 1000000000 AS Number;

This will produce the following output -

+------------+ | Number     | +------------+ | 100 | | 1000 | | 10000 | | 100000 | | 1000000 | | 10000000 | | 100000000 | | 1000000000 | +------------+ 8 rows in set (0.00 sec)
Updated on: 2019-09-03T08:24:56+05:30

755 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements