
- 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
How can I use MySQL subquery as a table in FROM clause?
We can use a subquery as a table in the FROM clause in the same way as the result of a subquery can be used with an operator in the WHERE clause. In the following example, we are using the result of subquery as a table by writing it after the FROM clause. It is mandatory to use an alias after subquery, here we are using alias ‘C_car’. To demonstrate it we are using the data as follows from table ‘Cars’ −
mysql> Select * from Cars; +------+--------------+---------+ | ID | Name | Price | +------+--------------+---------+ | 1 | Nexa | 750000 | | 2 | Maruti Swift | 450000 | | 3 | BMW | 4450000 | | 4 | VOLVO | 2250000 | | 5 | Alto | 250000 | | 6 | Skoda | 1250000 | | 7 | Toyota | 2400000 | | 8 | Ford | 1100000 | +------+--------------+---------+ 8 rows in set (0.02 sec) mysql> Select * FROM ( Select Name, Price from Cars Where Price > 200000) C_car WHERE Name = 'Nexa'; +------+--------+ | Name | Price | +------+--------+ | Nexa | 750000 | +------+--------+ 1 row in set (0.00 sec)
- Related Articles
- How can we use a MySQL subquery with FROM clause?
- How can we use MySQL SELECT without FROM clause?
- How can I use SPACE() function with MySQL WHERE clause?
- How to use actual row count (COUNT(*)) in WHERE clause without writing the same query as subquery in MySql?
- How can we use a MySQL subquery with INSERT statement?
- Get second largest marks from a MySQL table using subquery?
- How Can we use MySQL DISTINCT clause with WHERE and LIMIT clause?
- How can I return the values of columns from MySQL table as a set of values?
- Can we use “year” as a column came in a MySQL Table?
- How can I use MySQL INTERVAL() function with a column of a table?
- How can I drop an existing column from a MySQL table?
- Can we select second largest record from a table without using LIMIT clause in MySQL?
- How can we use ASCII() function with MySQL WHERE clause?
- How can we use CHAR_LENGTH() function with MySQL WHERE clause?
- How can we use BIN() function with MySQL WHERE clause?

Advertisements