
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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)
- Related Articles
- MySQL query to select multiple rows effectively?
- MySQL select query with multiple WHERE?
- How to get a specific column record from SELECT query in MySQL?
- MySQL query to select date from timestamp?
- Implement MySQL query using multiple OR statements. Any optimal alternative?
- MySQL query to select closest date from today?
- How can you order the result obtained by select query in MySQL?
- How to get multiple rows in a single MySQL query?
- MySQL query to get result by month and year based on condition?
- Set user variable from result of query in MySQL?
- MySQL query to select the values having multiple occurrence and display their count
- How to select first and last data row from a MySQL result?
- Insert values from the first table to the second table using two SELECT statements in a single MySQL query
- How to get file extension of file as a result of MySQL query?
- MySQL query to select all the records only from a specific column of a table with multiple columns

Advertisements