Knowledge Walls
Gopal Rao
Mumbai, Maharashtra, India
Passcode:
Subquery in sql server example in Queries of SQL Queries
2310 Views
Hints 
Sub query,In which query present inside query.Sub query normally written in where condition.The selected value from sub query act as a value to the where condition for main query.

In following example, The dept_no select by sub query act as value in where condition main query.
Syntax
select columnName from tableName where columnName=(select columnName from tableName where columnName='value');
Example
Get the employee numbers of all employees whose departments are located in Seattle.

select emp_no from Empolyee where dept_no=(select dept_no from Department where location='seattle');
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details