is it possile to select columns from 2 different tables?

Forum related to Firebird

Moderators: gto, cipto_kh, EgonHugeist

chunkiebone
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: 08.04.2013, 01:40

is it possile to select columns from 2 different tables?

Postby chunkiebone » 05.05.2013, 05:19

Hello I was just wondering if it is possible to select data from 2 tables using the zquery? I have tried this sql statement:

select * from "table1"

union

select * from "table2"


But it always gets an error. I was hoping that I can display on a TDbgrid data from 2 tables.

I am using delphi7 and firebird.

Thanks.

marsupilami
Gold Boarder
Gold Boarder
Posts: 671
Joined: 17.01.2011, 14:17

Postby marsupilami » 07.05.2013, 15:02

Hello chunkiebone,

this kind of setup works but it required that the two tables have exactly the same layout. I don't know for your database layout but you might want to use something similar to this:

Code: Select all

select cast(1 as smallint) as SRC, ID, NAME, FIRSTNAME from CONTACTS1
union all
select cast(2 as smallint) as SRC, ID, NAME, FIRSTNAME from CONTACTS2

But remember: For this to work your tables need a very similar layout - for example maybe NAME should be VARCAHR(50) on both. And it should not be VARCHAR(25) on the first and VARCHAR(50) on the second.
Best regards,

Jan


Return to “Firebird”

Who is online

Users browsing this forum: Bing [Bot] and 1 guest