How to Use Subqueries in SQL

In this article I am going to explain how to use Subqueries in SQL.
  • 2101

Introduction

In this article I am going to explain how to use Subqueries 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

Example

select * from mcninvoices

where invoicetotal >

( select avg(invoicetotal) from invoices )

Output 

Clipboard14.jpg


© 2020 DotNetHeaven. All rights reserved.