Subject Re: [firebird-support] UNION problem - column count error
Author PenWin
When executing the SELECT.

Pepak

----- Original Message -----
From: "Martijn Tonies" <m.tonies@...>
To: <firebird-support@yahoogroups.com>
Sent: Wednesday, December 27, 2006 1:11 PM
Subject: Re: [firebird-support] UNION problem - column count error


> Hi,
>
>> I am trying to write a view which puts together values from several
> tables.
>> All such tables have two columns, say "key" and "value". The SELECT
> command
>> looks something like this:
>>
>> SELECT key, value, 0, 0, 0 FROM table_A
>> UNION
>> SELECT key, 0, value, 0, 0 FROM table_B
>> UNION
>> SELECT key, 0, 0, value, 0 FROM table_C
>> UNION
>> SELECT key, 0, 0, 0, value FROM table_D
>>
>> The idea is that this SELECT will be used in a view and I'll combine all
>> values with
>>
>> SELECT key, SUM(value1), SUM(value2), SUM(value3), SUM(value4) FROM
> the_view
>>
>> But for some strange reason I am getting an error number -104 ("count of
>> column list and variable list do not match"). I even tried to CAST all
>> columns, without success - as soon as I try the first union, I get the
>> error. Is that a bug in Firebird (1.5.3 Win32 SuperServer) or did I miss
>> something?
>
> When are you getting that error, on executing your UNION select, or
> when creating the view? If the latter, try naming the columns:
>
> create view myview (key, value1, value2, value3, value4)
> as SELECT ...