Thread: Tablenames in Resultsets?

Tablenames in Resultsets?

From
gb@a3design.de
Date:
Hello there!

how do I get the tablenames in an resultset from an query like this:

imagine two tables with columns named id and value

test1:
id | value
------------
1  | hello
2  | goodbye

test2:
id | value
------------
1  | gunter
2  | heinz

select * from test1, test2 where test1.id=test2.id


the problem is:

my resultset looks like this:

id | value | id | value
------------------------
...

but I need:

test1.id | test1.value | test2.id | test2.value
-----------------------------------------------
...

because I dont want to access the fields by index but by name!!!

any suggestions?


Re: Tablenames in Resultsets?

From
Ivan Cornell
Date:
gb@a3design.de wrote:

> select * from test1, test2 where test1.id=test2.id
>
>
> but I need:
>
> test1.id | test1.value | test2.id | test2.value
> -----------------------------------------------
> ...
>
> because I dont want to access the fields by index but by name!!!
>

My solution would be
select t1.id as test1_id, t1.value as test1_value, t2_id as test2_id,
t2.value as test2_value from test1 t1, test2 t2 where t1.id = t2.id
You don't have to rename the tables (in this case to t1.t2), but it can
really reduce your query string length!

Ivan.




Re: Tablenames in Resultsets?

From
Papp Gyozo
Date:
Hi,

instead of
> select * from test1, test2 where test1.id=test2.id
use

SELECT test1.id AS "test1.id", test1.value, test2.id AS "test2.id",
test2.value FROM test1 , test2 WHERE test1.id = test2.id;

Papp Gyozo

s7461pap@hszk.bme.hu, gerzson17@freemail.hu