Advertisement
Advertisement


SQL WITH clause example


Question

I was trying to understand how to use the WITH clause and the purpose of the WITH clause.

All I understood was, the WITH clause was a replacement for normal sub-queries.

Can anyone explain this to me with a small example in detail ?

2017/05/23
1
213
5/23/2017 12:26:25 PM


This has been fully answered here.

See Oracle's docs on SELECT to see how subquery factoring works, and Mark's example:

WITH employee AS (SELECT * FROM Employees)
SELECT * FROM employee WHERE ID < 20
UNION ALL
SELECT * FROM employee WHERE Sex = 'M'
2017/05/23