How to Use IN Operator with Subquery in SQL

In this article I am going to explain how to use IN operator with subquery in SQL.
  • 2226

Introduction

In this article I am going to explain how to use IN operator with subquery in SQL. A select statement known as subquery if it is codded within another SQL statement. Subquery can return a single value or a result set. This result set may contain a single column or more than one column.

There are four way to create subquery in a SELECT statement.

  • In WHERE Clause
  • In HAVING Clause
  • In FROM Clause
  • In SELECT Clause

You can use IN operator with sub queries in SQL. In operator in SQL provide a list of values that are tested against the test expression.  

Example

SELECT * FROM dbo.mcnvendors
WHERE vendorid IN

SELECT vendorid FROM dbo.mcninvoices)

Output 

Clipboard02.jpg


© 2020 DotNetHeaven. All rights reserved.