Re: Which column is taken in JOIN with multiple columns and different content ?
- From: "Ed Prochak" <edprochak@xxxxxxxxx>
- Date: 6 Mar 2007 05:40:03 -0800
On Mar 2, 11:07 am, mer...@xxxxxxx (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
First, note that this is not an ORACLE specific question. you could
have asked this just as easily in comp.databases
Why don't you try it and see? Try to think about what "SELECT *"
means. How many columns should you get in the result of joining tablea
and tableb? what would you expect if col1 in tableb was named arthur?
What does your textbook say?
Who said anything about the two tables having to be merged? If the
entities you are modelling are two separate things then two separate
tables should exist. (example one table PERSON and one table COMPANY.
Both have phone numbers. You would not put them both in the same table
just because of that common attribute.)
You need to concentrate on your question. It is easy when you
understand what SQL queries really do. Think about it. experiment. You
cannot hurt anything with a SELECT statement.
It would be nice if you also let us know how you did.
Ed
.
- Prev by Date: Re: Which column is taken in JOIN with multiple columns and different content ?
- Next by Date: [Java DBMS_SQL.varchar2_table] How to pass an array from Java which maps to a PL/SQL table in oracle?
- Previous by thread: Re: Which column is taken in JOIN with multiple columns and different content ?
- Next by thread: I *want* to spool query text...
- Index(es):
Relevant Pages
|