Jump to content

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.