Re: select on multiple tables

From: Rene Pijlman <rpijlman(at)wanadoo(dot)nl>
To: "Carterette, Ben" <bcarterette(at)mail(dot)liberty(dot)k12(dot)mo(dot)us>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: select on multiple tables
Date: 2001-08-15 23:29:23
Message-ID: v41mnt8ccedcnitlkemhc6es2lv386n0i0@4ax.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On Wed, 15 Aug 2001 16:43:31 -0500, Ben Carterette wrote:
>I have a query like "SELECT * FROM table1, table2" and I want to read values
>out of a ResultSet. What if the two tables have column names in common and
>I can't predict the column numbers? Is there any way to get table1.id and
>table2.id? rs.getString tells me "The column name table1.id not found."

Does this also happen when you explicitly name the columns?

SELECT table1.id, ..., table2.id, ...
FROM table1, table2

Or if that doesn't help, try if a column label with the AS
clause works:

SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ]
* | expression [ AS output_name ] [, ...]
http://www.postgresql.org/idocs/index.php?sql-select.html

SELECT table.id AS id1, ..., table2.id AS id2
FROM table1, table2

And then rs.getString("id1");

I think both solutions should work. Please let us know if they
don't.

Regards,
René Pijlman

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Barry Lind 2001-08-15 23:58:42 Re: [PATCHES] patch for JDBC PreparedStatement
Previous Message Carterette, Ben 2001-08-15 21:43:31 select on multiple tables