| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |

01-12-04, 10:05
|
|
Registered User
|
|
Join Date: Jul 2003
Posts: 50
|
|
|
SQL / UNION / temporary table
|
|
Hi
I have the following query:
Select distinct FK_ADRESSE_UUID from ADU.UTADU_DET_PRAEMIE where UNTERBRANCHE in ( 93001,93006,93009,98020,98021,98027,99020,99021,99 023,99024,99027,99028,99029 ) and STATUS <> 4 and (PLZ='8600')
UNION
Select distinct FK_ADRESSE_UUID from ADU.UTADU_VERTRAG where BRANCHE in ( 94,52010,88000,89000 ) and STATUS <> 4 and (PLZ='8600')
How can I get the number of rows of the result WITHOUT use of a temporary table ?
(UDB 8.1, Unix)
Marc
|
|

01-12-04, 11:16
|
|
Registered User
|
|
Join Date: Jan 2003
Posts: 3,575
|
|
Marc,
Try:
with temp1 as (Select distinct FK_ADRESSE_UUID from ADU.UTADU_DET_PRAEMIE where UNTERBRANCHE in ( 93001,93006,93009,98020,98021,98027,99020,99021,99
023,99024,99027,99028,99029 ) and STATUS <> 4 and (PLZ='8600')
UNION
Select distinct FK_ADRESSE_UUID from ADU.UTADU_VERTRAG where BRANCHE in ( 94,52010,88000,89000 ) and STATUS <> 4 and (PLZ='8600') ) select count(*) from temp1;
HTH
Andy
|
|

01-13-04, 03:47
|
|
Registered User
|
|
Join Date: Jan 2003
Posts: 1,570
|
|
|
|
Hi,
Solution of ARwinner also generates temporaly table.
I thing there is no way you can do it without temporaly table.
Hope this helps,
Grofaty
|
|

01-13-04, 07:51
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
|
|
tip: remove the DISTINCT from each of the subqueries in the union, it is not necessary because UNION itself removes duplicate rows
does this work? i don't have db2 to test on --
Code:
select count(*)
from (
select FK_ADRESSE_UUID
from ADU.UTADU_DET_PRAEMIE
where UNTERBRANCHE
in ( 93001,93006,93009,98020,98021,98027
, 99020,99021,99023,99024,99027,99028,99029 )
and STATUS <> 4
and PLZ='8600'
union
select FK_ADRESSE_UUID
from ADU.UTADU_VERTRAG
where BRANCHE
in ( 94,52010,88000,89000 )
and STATUS <> 4
and PLZ='8600'
)
|
|

01-15-04, 08:21
|
|
Registered User
|
|
Join Date: Jul 2003
Posts: 50
|
|
Thanks, it works like this:
select count(*) from (select FK_ADRESSE_UUID from ADU.UTADU_DET_PRAEMIE where UNTERBRANCHE in ( 93001,93006,93009,98020,98021,98027 , 99020,99021,99023,99024,99027,99028,99029 ) and STATUS <> 4 and PLZ='8600'union select FK_ADRESSE_UUID from ADU.UTADU_VERTRAG where BRANCHE in ( 94,52010,88000,89000 ) and STATUS <> 4 and PLZ='8600' ) as T
-> I had to put "as T" at the end of your statement
Marc
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|