Jump to content

multiple similar tables


granger

Recommended Posts

First of all, thanks in advance for any suggestions. I am relatively new to both php and mysql.

 

I have a bunch of tables that use the similar names and exact fields. Below is a snippet of them...

 

table_1: id, team, w, l, rating, rank...

table_2: id, team, w, l, rating, rank...

table_3: id, team, w, l, rating, rank...

 

the teams and ids are all the same in each table, as this data is taken over time.

 

I want the quickest/best way to output a table with the following way...

 

team, rank(table_1), rating (table_1), rank(table_2), rating (table_2), rank(table_3), rating (table_3)

 

ordered by the rank(table_1) ASC

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/138915-multiple-similar-tables/
Share on other sites

  • 2 weeks later...

OK, so that really didn't seem to help since all of the fields within the tables have the same names (either that or I am pulling it out wrong)... Let me give a better example...

 

table_1: id, team, W, L, Rating, Rank

1001, Abbott, 10, 1, 105, 1

1002, Gordon, 9, 2, 100, 2

1003, Strawn, 10, 3, 90, 3

 

table_2: id, team, W, L, Rating, Rank

1001, Abbott, 10, 1, 103, 1

1002, Gordon, 9, 2, 97, 3

1003, Strawn, 10, 3, 99, 2

 

table_3: id, team, W, L, Rating, Rank

1001, Abbott, 10, 1, 110, 1

1002, Gordon, 9, 2, 108, 2

1003, Strawn, 10, 3, 96, 3

 

Ok, so I want to have a query that gives me the following

id, Team, W, L, Rating_1, Rank_1, Rating_2, Rank_2, Rating_3, Rank_3

1001, Abbott, 10, 1, 105, 1, 103, 1, 110, 1

1002, Gordon, 9, 2, 100, 2, 97, 3, 108, 2

1003 Strawn, 10, 3, 90, 3, 97, 2, 96, 3

 

From my understanding, UNIONS and JOIN eliminate fields with the same name, thus I get only one of the rankings or ratings.... do I need to alias the fields within the query? If so, how?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.