SQL - Query Block, Sub Query

1 - About

A query can contain one or several subquery. A subquery is also known as query block.

3 - Example


SELECT e.ename, e.sal      
  FROM (SELECT *
          FROM emp e
         WHERE e.sal > 300
           AND e.deptno IN (SELECT d.deptno
                              FROM dept d
                             WHERE d.dname IN ('SALES', 'ACCOUNTING'))) e

This query contain 3 query block :

  • last

SELECT d.deptno
          FROM dept d
         WHERE d.dname IN ('SALES', 'ACCOUNTING')

  • second :

SELECT *
          FROM emp e
         WHERE e.sal > 300
           AND e.deptno IN ('last query block')

  • main query block

SELECT e.ename, e.sal      
  FROM ('second query block')


Data Science
Data Analysis
Statistics
Data Science
Linear Algebra Mathematics
Trigonometry

Powered by ComboStrap