Can we have multiple "WITH AS" in single sql - Oracle SQL

user1933888 picture user1933888 · Oct 29, 2013 · Viewed 179.7k times · Source

I had a very simple question: Does oracle allow multiple "WITH AS" in a single sql statement.

Example:

WITH abc AS( select ......)

WITH XYZ AS(select ....) /*This one uses "abc" multiple times*/

Select ....   /*using XYZ multiple times*/

I can make the query work by repeating the same query multiple times, but do not want to do that, and leverage "WITH AS". It seems like a simple requirement but oracle does not allow me:

ORA-00928: missing SELECT keyword

Answer

Deepshikha picture Deepshikha · Oct 29, 2013

You can do this as:

WITH abc AS( select
             FROM ...)
, XYZ AS(select
         From abc ....) /*This one uses "abc" multiple times*/
  Select 
  From XYZ....   /*using abc, XYZ multiple times*/