Reputation: 3
From oracle doc http://docs.oracle.com/javase/1.5.0/docs/guide/jdbc/getstart/resultset.html
In some cases, it is possible for an SQL query to return a result set that has more than one column with the same name. If a column name is used as the parameter to a getXXX method, getXXX will return the value of the first matching column name.
Anybody knows about "some cases"?
Upvotes: 0
Views: 258
Reputation: 26454
Here's a common example:
SELECT * FROM table1 JOIN table2 ON table1.table1Id = table2.table1Id;
Here you know table1
and table2
have a column named table1Id
, and it is guaranteed to have the same value. However if you have a self-join:
SELECT * FROM employee e JOIN employee m ON e.manager_id = m.id;
Now you have a problem and, probably, your result set will not make as much sense.
Upvotes: 0
Reputation: 1507
Imagine two tables defined as
where one would want to list books with author information using the following SQL
SELECT *
FROM Books
JOIN Authors USING (AuthorId)
Now you have two unrelated title
columns in the ResultSet
, one being the title of the book and one being the (e.g. academic) title of the author.
Upvotes: 0
Reputation: 22811
The simplest case is
select 1 as A, 2 as A from dual
much the same way someone may (unwillingly) create equal aliases in a complex query.
Upvotes: 2