How to Write Sub-Query in Where Clause Explained

A QUERY WITHIN THE QUERY is called sub-query. Here’s an example with or without sub-query that tells how to write quickly.

SQL Without Sub-query

Select employee_name
from employee
where dept_no in (100,200);

From the above query, you can understand that the values in the brackets act as a sub Query. Really simple. Also You May Like: Top Rules You Need to Write a Sub Query

SQL With Sub-query

Here sub query will supply a list of values.

Select *
From employee
where dept_no in (
select dept_no
from dept);

Here, the inner SELECT supplies list of department numbers. For example 100, 200, 300, 400 etc. This way you can write any sub-query quickly.

Related Posts

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.