articles

Home / DeveloperSection / Articles / subquery in sql with example

subquery in sql with example

Anonymous User 1853 12-Jul-2018

Introduction:

In this article, we are going to explain what is subquery in SQL or how to create subquery in SQL or how to use a subquery in SQL server with the example.

Description:

A subquery is a SQL query within a query. Subqueries are nested queries that provide data to the enclosing query. Subqueries can return individual values or a list of records, Subqueries must be enclosed with round brackets.

There is no general syntax; subqueries are regular queries placed inside round brackets. Subqueries can be used in different ways and at different locations inside a query:  

Here is a subquery with the IN operator.

Let’s see simply subquery in SQL Server

Customer Table

subquery in sql with example

OrderDetails Table

subquery in sql with example

Subquery with the IN operator. 

SELECT ID,NAME,ADDRESS1 FROM CUSTOMER

     WHERE ID IN (SELECT ID FROM orderDetails WHERE AMOUNT=10000)

In above example, we have a customer table and orderdetails table, we have created a subquery which is return customer details, which customer order amount equal 10000

OutPut:

subquery in sql with example

i hope it will help you after reading it.

you might also like to read next topic  create a simple cursor in sql server, how to import excel data in sql server database, Types Of Join in Sql Server, Union Example in SQL Server, Trigger in SQL



Updated 07-Sep-2019
I am a content writter !

Leave Comment

Comments

Liked By