Subject | Re: [firebird-support] Combine 2 tables |
---|---|
Author | Arno Brinkman |
Post date | 2004-06-07T12:02:11Z |
Hi,
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
> How can i combine 2 tables without a where clause and so that i canYou can do that with UNION ALL :
> "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.
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