---
title: "What is subquery?"  
description: "What is subquery?"  
author: "Anonymous User"  
published: 2019-07-04  
updated: 2020-09-21  
canonical: https://www.mindstick.com/interview/23532/what-is-subquery  
category: "mssql server"  
tags: ["sql server", "sql server 2008", "sql server 2012"]  
reading_time: 2 minutes  

---

# What is subquery?

The subquery is a query within another query. The outer query is called as the main query, and the inner query is called subquery. The SubQuery is always executed first, and the result of the subquery is passed on to the main query.

- The subquery is a SQL query within a query.
- The subqueries are nested queries that provide data to the enclosing query.
- The subqueries can return individual values or a list of records
- The subqueries must be enclosed with parenthesis

```
Example:-
SELECT column_name
FROM table_name
WHERE column_name expression operator
    ( SELECT COLUMN_NAME  from TABLE_NAME   WHERE ... );
```

```
Select NAME, LOCATION, PHONE_NUMBER from DATABASE
WHERE ROLL_NO IN
(SELECT ROLL_NO from STUDENT where SECTION=’A’); 
```

## Answers

### Answer by Anonymous User

The subquery is a query within another query. The outer query is called as the main query, and the inner query is called subquery. The SubQuery is always executed first, and the result of the subquery is passed on to the main query.

- The subquery is a SQL query within a query.
- The subqueries are nested queries that provide data to the enclosing query.
- The subqueries can return individual values or a list of records
- The subqueries must be enclosed with parenthesis

```
Example:-
SELECT column_name
FROM table_name
WHERE column_name expression operator
    ( SELECT COLUMN_NAME  from TABLE_NAME   WHERE ... );
```

```
Select NAME, LOCATION, PHONE_NUMBER from DATABASE
WHERE ROLL_NO IN
(SELECT ROLL_NO from STUDENT where SECTION=’A’); 
```


---

Original Source: https://www.mindstick.com/interview/23532/what-is-subquery

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
