Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"with... as" in SQL Navigator

Tags:

sql

oracle

The following query works:

select count(*) from everything where num not in (select num from sometable)

The following query is supposed to be equivalent to the above, but results in an "invalid identifier" error:

with unwanted as (select num from sometable)
select count(*) from everything where num not in unwanted

What is wrong with the second query?

like image 289
snakile Avatar asked Oct 02 '12 14:10

snakile


People also ask

Can we use with within a with in SQL?

No, you can't define a CTE within a CTE, however you can define multiple CTE's and reference other CTE's in a single statement.

What does as stand for in SQL?

The AS command is used to rename a column or table with an alias. An alias only exists for the duration of the query.

How do I change the width in SQL?

You can change the displayed width of a datatype or DATE, by using the COLUMN command with a format model consisting of the letter A (for alphanumeric) followed by a number representing the width of the column in characters. If you specify a width shorter than the column heading, SQL*Plus truncates the heading.

What is SQL Navigator used for?

SQL Navigator for Oracle helps you write better code faster. Deliver high-quality applications faster than ever by being able to write, edit and maintain database objects through automation and an intuitive graphical interface.


1 Answers

the syntax is like this:

with unwanted as (select num from sometable)
select count(*) from everything where num not in (select * from unwanted)

obviously this makes only sense if the select num from sometable part is a bit more complex or used several times later...

like image 143
bw_üezi Avatar answered Sep 28 '22 18:09

bw_üezi