
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- How can we use a MySQL subquery with FROM clause?
- How can I use SPACE() function with MySQL WHERE clause?
- How can we use MySQL SELECT without FROM clause?
- How can we use a MySQL subquery with INSERT statement?
- How to use actual row count (COUNT(*)) in WHERE clause without writing the same query as subquery in MySql?
- Get second largest marks from a MySQL table using subquery?
- How can I return the values of columns from MySQL table as a set of values?
- How can I drop an existing column from a MySQL table?
- How can I use MySQL INTERVAL() function with a column of a table?
- How can we fetch a particular row as output from a MySQL table?
- How Can we use MySQL DISTINCT clause with WHERE and LIMIT clause?
- How can we nest a subquery within another subquery?
- How can I use a SELECT statement as an argument of MySQL IF() function?
- Can we use “year” as a column came in a MySQL Table?
- How can I delete MySQL temporary table?
Advertisements