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.
is it possile to select columns from 2 different tables?
Moderators: gto, cipto_kh, EgonHugeist
-
- Fresh Boarder
- Posts: 5
- Joined: 08.04.2013, 01:40
-
- Platinum Boarder
- Posts: 1956
- Joined: 17.01.2011, 14:17
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:
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
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
Best regards,
Jan