0% found this document useful (0 votes)
6 views5 pages

T-SQL Subquery - Write Subquery in Select Statement

The document provides an overview of T-SQL subqueries, defining them as nested SQL queries within other statements. It explains the use of logical operators such as IN, ANY, SOME, EXISTS, and NOT EXISTS in conjunction with subqueries, along with examples for each operator. The content is part of a broader T-SQL tutorial covering various SQL functions and concepts.

Uploaded by

samcol.teste
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

T-SQL Subquery - Write Subquery in Select Statement

The document provides an overview of T-SQL subqueries, defining them as nested SQL queries within other statements. It explains the use of logical operators such as IN, ANY, SOME, EXISTS, and NOT EXISTS in conjunction with subqueries, along with examples for each operator. The content is part of a broader T-SQL tutorial covering various SQL functions and concepts.

Uploaded by

samcol.teste
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

27/04/22, 09:38 T-SQL Subquery - Write subquery in select statement

T-SQL Tutorial

T-SQL Tutorial
Functions

Operators

Data Types

Select Query

Table Joins

Stored Procedures

System Stored Procedures

Triggers

Views

Cursors

Backup / Restore

Transactions

SET Statements

Constraints

Subquery

Statements

Variables

Aggregate functions

Analytic functions

Conversion functions

T-SQL Subquery
What is a Subquery
A SQL Subquery(also called an inner query or inner select) is a sql query that is nested inside a statement(SELECT, INSERT, UPDATE, or
DELETE), or inside another subquery.

Subquery basics
The statements that include a SQL Subquery usually use logical operators(in, exists, all, any or some):

WHERE expression [NOT] IN (subquery)


WHERE expression comparison_operator [ANY | ALL | SOME] (subquery)
WHERE [NOT] EXISTS (subquery)

[Link] 1/5
27/04/22, 09:38 T-SQL Subquery - Write subquery in select statement

[Link]
[Link]

[Link]
Get your Degree | Become
Best
Open

Subquery examples

IN
The IN operator verify that the value in a specified column matches any value in a subquery or list.

select * from EMPLOYEES E

where [Link] IN (select [Link] from Sales s);

ANY
The ANY operator compares a scalar value with a single-column set of values.

select * from Customers c

where [Link] = ANY (select [Link] from Sales s);

SOME
The SOME operator is equivalent with ANY operator.

select * from Students s

where [Link] =SOME (select l.Student_id from Library l);

EXISTS
The Transact-SQL EXISTS operator specifies a subquery to check for the existence of rows.

select * from Students s

where EXISTS (select * from Students_Math m where [Link]=[Link]);

NOT EXISTS
The Transact-SQL NOT EXISTS operator specifies a subquery to check for the not existence of rows.

select * from Students s

where NOT EXISTS (select * from Students_Math m where [Link]=[Link]);

Your Success is waiting You Write With Confidence


Ad Atlantic Int'l University Ad Grammarly

[Link] 2/5
27/04/22, 09:38 T-SQL Subquery - Write subquery in select statement

Download The Free eBook Novo CorelDRAW® Graphics Suite


Ad TestRail Ad CorelDRAW

Private Internet Access™ VPN We Do Silo


Ad Private Internet Access Ad Sarcon

STCW Security Awareness Course US GooglePlay Gift Card 10 Lower


Ad [Link] Price
Ad [Link]

A porta para o web3 Gestão Financeira Automatizada


Ad Opera Crypto Browser Ad Equals

[Link] 3/5
27/04/22, 09:38 T-SQL Subquery - Write subquery in select statement

[Link] 4/5
27/04/22, 09:38 T-SQL Subquery - Write subquery in select statement

Main Topics

Error messages

PDF T-SQL tutorial

T-SQL Interview Questions

SQL Tutorial

SQL examples

SQL Server examples

T-SQL examples

Articles

Difference between Union and Union All

Difference between Char and Varchar

Difference between Delete and Truncate

Contact Us
Contact us about any information regarding this TSQL Tutorial and we will be happy to respond as quickly as possible: info@[Link]

Copyright © 2012 - 2022 | [Link] | Contact Us | Privacy Policy

[Link] 5/5

You might also like