dcsimg
Retrieving data from joins
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Alexander_Rudyj
Posted On:   Thursday, July 11, 2002 12:46 AM


Following query



select * from a,b where a.bref = b.id order by a.name




How can I access the coulmn name if both tables have a "name" column?




getString("a.name") on a ResultSet instance does'nt work
even if I write




select a.name, b.name from a,b .......




Thanks

Re: Retrieving data from joins

Posted By:   Simon_Ablett  
Posted On:   Thursday, July 11, 2002 02:33 AM

Assume that your query does a join across three tables returning a single field called 'name' from each. Then you could use the following form...


String name1 = rslt.getString(1);
String name2 = rslt.getString(2);
String name3 = rslt.getString(3);



i.e. use the index values rather than referencing by field name.

Regards.

Re: Retrieving data from joins

Posted By:   Lasse_Koskela  
Posted On:   Thursday, July 11, 2002 01:01 AM

You can use alias names for the retrieved columns:


SELECT a.name AS a_name, b.name AS b_name, b.something_else FROM a, b WHERE a.bref = b.id ORDER BY a.name


This will return the following columns:

a_name

b_name

something


Please, correct me if my quick hack contains errors (as usual:)

About | Sitemap | Contact