SELECT Statement WHERE ColumnName [Comparison Operator] (SELECT Statement / Values)
Results of one Sql query or Sql statement as the input for another Select query, Insert Into query, Insert From query, Update query and Delete query.
You also can use the result of Subquery as a search condition for using in the IN( ) function or EXISTS operator.
Comparison Operator such as =, >, <, >=, <=, LIKE, IN
Below is example for SQL UNION
Company | Sales($) | Website |
Sql Traniner | 2500 | http://www.sqltutorials.blogspot.com |
BeautyCentury | 3000 | http://beautycentury.blogspot.com |
TravelYourself | 2800 | http://travelyourself.blogspot.com |
Sales | Website |
2900 | http://www.sqltutorials.blogspot.com |
3000 | http://beautycentury.blogspot.com |
2800 | http://travelyourself.blogspot.com |
SQL Subquery Statement
SELECT * FROM TABLE1 WHERE sales in (SELECT Sales FROM TABLE2)
Result
BeautyCentury | 3000 | |
TravelYourself | 2800 | http://travelyourself.blogspot.com |
SELECT * FROM TABLE1 WHERE sales LIKE (SELECT Sales FROM TABLE2 WHERE Sales <2900)>
Result
TravelYourself | 2800 | http://travelyourself.blogspot.com |
SELECT * FROM TABLE1where sales > (SELECT Sales FROM TABLE2 WHERE Sales <2900)
Result
BeautyCentury | 3000 | http://beautycentury.blogspot.com |