|
 |
db2 thread: RE: DB2 SQL with UNION ... HELP!!
Message #1 by "Brett A. Phipps" <phipywr@d...> on Fri, 8 Feb 2002 16:43:07
|
|
Your SQl does not look correct to me. I'm assuming you only pasted a
portion of your query. Nevertheless, I've never seen the 'with' statement
before so I looked it up in my DB2 book. It shows this:
The syntax for defining a table column (is that why the with statement is
there?)
column-name data-type [NOT NULL] [{PRIMARY KEY | UNIQUE}] [[WITH] DEFAULT
[default-value]] [check-constraint]
That is obviously not congruent with the statement you have below as you
are using the column name after the word parent and then you are trying to
define the column name with a subselect. This makes no sense to me
whatsoever.
What I'm familiar with would be something like:
select a.column-name1 as "name_i_choose"
from my-database a
where a.column-name = 'some-value'
union
select b.column-name1 as "name_i_choose"
from my-database b
where b.column-name = 'some-different-value'
;
Additionally what's the second select for at the bottom?
> Here is one SQL Statement that I had tried. If it helps any, I'm using
> this against a DB2 V.5 Database. It gives me an error of ILLEGAL SYMBOL
(.
> I understand that this is the SQL92 version of the RECURSIVE UNION
> statement.
>
> WITH PARENT (parent_catalog_id, child_catalog_id) AS
> ( SELECT parent_catalog_id
> , child_catalog_id
> FROM cis.catalog_tree
> WHERE parent_catalog_id = 1105
> UNION ALL
> SELECT TREE.parent_catalog_id
> , TREE.child_catalog_id
> FROM cis.catalog_tree AS TREE
> , PARENT AS PAR
> WHERE PAR.catalog_id = TREE.parent_catalog_id
> )
> SELECT parent_catalog_id, child_catalog_id
> FROM PARENT ;
|
|
 |