Subject Re: [firebird-support] Combine 2 tables
Author Arno Brinkman
Hi,

> How can i combine 2 tables without a where clause and so that i can
> "rename" 1 field of each table to 1 single field in my resultset?
>
> Table 1:
> someName varchar,
> someOtherStuff varchar,
> ....
>
> Table 2:
> otherName varchar,
> otherStuff varchar,
> ....
>
> Result:
> name varchar, // Where name is either someName or otherName
> someOtherStuff varchar, // if name is from someName not null
> otherStuff varchar, // if name is from otherName not null
> ....
>
> There is no field that has to be compared, i only want the total
> selection of both tables with some fields renamed so they match the
> same field name as the ones in the other table.

You can do that with UNION ALL :

SELECT
SomeName AS Field1,
SomeOtherStuff AS Field2
FROM
Table1
UNION ALL
SELECT
OtherName,
SomeOtherStuff
FROM
Table2

NOTE! If both fields from table1 and table2 have a different datatype/length
then you must cast 1 of them to the same datatype/length as the other one.

Regards,
Arno Brinkman
ABVisie

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Firebird open source database (based on IB-OE) with many SQL-99 features :
http://www.firebirdsql.org
http://www.firebirdsql.info
http://www.fingerbird.de/
http://www.comunidade-firebird.org/

Support list for Interbase and Firebird users :
firebird-support@yahoogroups.com

Nederlandse firebird nieuwsgroep :
news://newsgroups.firebirdsql.info