Joining

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Joining

Post by Shendemiar »

I have two tables like

Table A
Index1, Index2, Location

Table B
Index1, Index2, Result_type, Result
(So each row represents one result_type & result pair)

And i'd like to have a table like
Index1, Index2, Location, Result, Result, Result...
(Where all results are inserted in predefined resulttype columns like Tempereture, Oxygen etc...)
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Needs rewriting, but the basics are there. The problem with joining tables that have the same fieldsnames on both, are that the query itself will not know what (in this case) index1 is witch etc.

But by naming them as in the example, you can bypass this.

Code: Select all

select 
 tablea.index1 as 'a-index1',
 tablea.index2 as 'a-index2',
 tablea.location,
 tableb.index1 as 'b-index1',
 tableb.index2 as 'b-index2',
 tableb.result_type as 'restype',
 tableb.result
from
 tablea
 inner join tableb on tablea.index1 = tableb.index1
Hope it gave you enough ideas to work with.
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

I did it with multipple updates.... 49 in fact. Not very fancy but i got it.
Post Reply