In Oracle SQL Developer, I use the WITH clause in this (simplified) way:
WITH foos AS SELECT * FROM my_table WHERE field = 'foo' bars AS SELECT * FROM my_table WHERE field = 'bar' SELECT * FROM foo INNER JOIN bar ON foo.id = bar.id
I would like to be able to separate the lines "foo" and "bar" so that I have something like:
WITH subq(my_arg) AS SELECT * FROM my_table WHERE field = my_arg SELECT * FROM subq('foo') INNER JOIN subq('bar') ON subq('foo').id = subq('foo').id
Because foos and bars are actually much bigger than that, and there are nuts, only two of them, so itβs a little difficult to maintain.
I know this may not be possible with the WITH clause, but what would be the best solution to avoid writing this subquery several times? It might be pretty simple, but I'm completely new to SQL ...
Thanks for your help.
source share