Using Subquery in a SQL Select Statement

In SQL, a subquery or nested query is query inside the main query. Here are some examples of how subqueries can be used:

select c.customerId  from 
(
 select firstname, lastname, customerId from customers
) c

Here is a subquery inside a join clause:

select c.customerId, t.type from customers c
join 
(
  select typeid, type from types
  where active = 1
) as t on c.typeid = t.typeid

 

Leave a Reply

Your email address will not be published. Required fields are marked *