You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Luis Angel Fernandez Fernandez <la...@gmail.com> on 2007/11/14 17:44:29 UTC

What's the name of a column...

  Hi!

  I execute a query like this: select MAX(idstat) from history;

  Now, from the ResultSet, how can I get the data by column name?

  Using rs.getString() with idstat, MAX(idstats)... I get column not
found. There is an idstat field. What's the name for that kind of
columns? I did some searches with no success.

  Bye!

Re: What's the name of a column...

Posted by Bryan Pendleton <bp...@amberpoint.com>.
>   I execute a query like this: select MAX(idstat) from history;
> 
>   Now, from the ResultSet, how can I get the data by column name?

Try using the "as" keyword to provide a name for your column:

   select max(idstat) as max_idstat from history;

Then you should be able to fetch the data by column name "max_idstat".

thanks,

bryan



Re: What's the name of a column...

Posted by Kurt Huwig <k....@iku-ag.de>.
Am Mittwoch, 14. November 2007 schrieb Luis Angel Fernandez Fernandez:
>   Hi!
>
>   I execute a query like this: select MAX(idstat) from history;
>
>   Now, from the ResultSet, how can I get the data by column name?
>
>   Using rs.getString() with idstat, MAX(idstats)... I get column not
> found. There is an idstat field. What's the name for that kind of
> columns? I did some searches with no success.

SELECT MAX(idstat) AS m FROM history;

then request "m"
-- 
Mit freundlichen Grüßen

Kurt Huwig

GnuPG 1024D/99DD9468 64B1 0C5B 82BC E16E 8940  EB6D 4C32 F908 99DD 9468

Re: What's the name of a column...

Posted by Mamta Satoor <ms...@gmail.com>.
The column name for the first column of select MAX(idstat) would be
'1'. I tried following in ij and it shows what is the column name
assigned when the query has aggregate functions.

ij> create table t1(c11 int, c12 int);
0 rows inserted/updated/deleted
ij> select max(c11), max(c12) as col1 from t1;
1          |COL1
-----------------------
NULL       |NULL
1 row selected
ij> select max(c11), max(c12)  from t1;
1          |2
-----------------------
NULL       |NULL
1 row selected
ij> select max(c11) as col1, max(c12)  from t1;
COL1       |2
-----------------------
NULL       |NULL
1 row selected

On 11/14/07, Mark Thornton <mt...@optrak.co.uk> wrote:
> Luis Angel Fernandez Fernandez wrote:
> >   Hi!
> >
> >   I execute a query like this: select MAX(idstat) from history;
> >
> >   Now, from the ResultSet, how can I get the data by column name?
> >
> >   Using rs.getString() with idstat, MAX(idstats)... I get column not
> > found. There is an idstat field. What's the name for that kind of
> > columns? I did some searches with no success.
> >
> >   Bye!
> >
> That column doesn't have a name unless you write the query as something like
>
> select MAX(idstat) as "maxIdStat" from history
>
> Regards
> Mark Thornton
>
>

Re: What's the name of a column...

Posted by Mark Thornton <mt...@optrak.co.uk>.
Luis Angel Fernandez Fernandez wrote:
>   Hi!
>
>   I execute a query like this: select MAX(idstat) from history;
>
>   Now, from the ResultSet, how can I get the data by column name?
>
>   Using rs.getString() with idstat, MAX(idstats)... I get column not
> found. There is an idstat field. What's the name for that kind of
> columns? I did some searches with no success.
>
>   Bye!
>   
That column doesn't have a name unless you write the query as something like

select MAX(idstat) as "maxIdStat" from history

Regards
Mark Thornton


Re: What's the name of a column...

Posted by Thomas Kellerer <sp...@gmx.net>.
Luis Angel Fernandez Fernandez wrote on 14.11.2007 17:44:
>   Hi!
> 
>   I execute a query like this: select MAX(idstat) from history;
> 
>   Now, from the ResultSet, how can I get the data by column name?
> 
>   Using rs.getString() with idstat, MAX(idstats)... I get column not
> found. There is an idstat field. What's the name for that kind of
> columns? I did some searches with no success.

You don't need a name. You get use getString(1)