Subject Re: [firebird-support] UNION problem - column count error
Author Martijn Tonies
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 ...


Martijn Tonies
Database Workbench - development tool for Firebird and more!
Upscene Productions
http://www.upscene.com
My thoughts:
http://blog.upscene.com/martijn/
Database development questions? Check the forum!
http://www.databasedevelopmentforum.com