Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Which column is taken in JOIN with multiple columns and different content ?
On Mar 2, 11:07 am, mer..._at_gmx.net (Tobias Merler) wrote:
> Assume I join two tables.
> Both of these tables contain a column with name "col1". This column ist not he primary key.
> However this column contains different values which value is taken ?
>
> Lets see the following example:
>
> Select *
> FROM tablea a, tableb b
> Where a.id = b.id
>
> tablea:
>
> id col1 col2
>
> 1 aaa ddd
> 2 bbb eee
> 3 ccc fff
>
> tableb:
>
> id col1 col3
>
> 1 zzz uuu
> 2 xxx vvv
> 3 yyy www
>
> The result table will look like:
>
> id col1 col2 col3
>
> 1 ??? ddd uuu
> 2 ??? eee vvv
> 3 ??? fff www
>
> Which values will be for the questions marks ?
>
> Ok, I know the data model is not perfect and the two tables could be merged.
> But keep in mind that the sample is only a simplified version of a more complex
> SQL statement. So lets concentrate on my question.
>
> Thank you
>
> Toby
Did you try running these statements against oracle?
You might be surprised at what happens.
Do you think only 1 column with name of id will be returned from select * or is it more than that? What will each one be named? How about for col1?
In cases like this you want to be in control and select exactly the columns that you want returned ... a.col1, b.col2 etc. Received on Fri Mar 02 2007 - 12:09:44 CST
![]() |
![]() |