db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steffen Winkler" <steffen.wink...@danprodukte.de>
Subject AW: Tablealias as column qualifier in resultset
Date Thu, 07 Dec 2006 06:59:31 GMT
For cases where the same column names appear in joins of two tables, you can
use column-Alias, e.g.:

 SELECT  t.TABLENAME AS TABLENAME
       , t2.TABLENAME AS REFTABLENAME
   FROM  SYSTABLES t
      ,  SYSTABLES t2
 WHERE ...

resultSet.getString( TABLENAME );
resultSet.getString( REFTABLENAME );

-----Urspr√ľngliche Nachricht-----
Von: Rajesh Kartha [mailto:kartha02@gmail.com]
Gesendet: Mittwoch, 6. Dezember 2006 14:10
An: Derby Discussion
Betreff: Re: Tablealias as column qualifier in resultset


Per Newgro wrote:

>Hi,
>
>i've a little question.
>If i execute the example-statement
>
>  SELECT MYTABLE.* FROM myTable MYTABLE WHERE MYTABLE:A = 5;
>
>i expected to access the column in resultset by usage of
>
>  Object o = getObject("MYTABLE.A);
>
>But this is throwing a ColumnNotFoundException. The other access is
working.
>
>  Object o = getObject("A);
>
>I'm a little bit confused because how is derby solving same column names in
a
>join of two tables, if the columns are not referenced by the qualifier?
>
>Cheers
>Per
>
>
>
Hello Per,

I have never seen any examples of using "tableName.columnName" with the
ResultSet.getObject() method.
My understanding   is  the ResultSet.getObject () is expected to use
only the column names, hence using
the table name qualifier will  not work.  Using only the column names
should be right approach as
you noticed (getObject("A"))

For cases where the same column names appear in joins of two tables, I
would qualify those
columns with the respective tables in the query and  use the
*getObject*(int columnIndex)  instead:

Example; select a.b,b.b from a, b where a.a=b.a


HTH,
Rajesh


Mime
View raw message