Relationship between tables in Mysql

Asked

Viewed 601 times

1

I am creating a site and I have a problem in it, in this site I will display some characters of the game League of Legends and I will show which character is strong or weak in relation to others, for example Character 1 is strong against Character 2 but is weak against Character 3.

I own the table CAMPEOES and registered there:
| champ_id | champ_nome | champ_descricao | champ_avatar |

To create this relationship I will need to create another table to relate them or I can do something on the championship table itself since it has the information I will need that are champ_nome and champ_avatar.

Characters can be related to several other characters at the same time.

  • 1

    I believe it is better to create another structure. Or a table, or two. A table (champ_id_principal, champ_id_secundario, relacao), where champ_id_principal is strong or weak in relation to the secondary, so the field relation. Or two tables. "tbl_fortes", champ_prin, champ_sec. where the main is stronger than sec, and the same idea for the "tbl_fracos". It’s up to you, it’s a matter of opinion what you’re looking for...

  • Okay, I get it, but I can’t think of how SELECT to display the information, this question of relationship between tables confuses me enough.

  • It depends on which structure you want to follow... you can define it and edit your question by placing the tables, which someone will help to assemble your select :)

  • You are making the question broad by asking multiple questions on a single topic. At first you wanted to know how to do the relationship of two tables, now you are asking about how to perform the select. So the question about the relationship of the tables has been solved? The problem now is only the select?

  • Yes Renan, sorry for this inconvenience the problem of the relationship was solved now I’m trying to figure out how would be the correct SELECT to bring the names of champions. I didn’t think it was right to ask another question to solve a related question.

  • @Felipedumont You can post the resolution as an answer to this question, giving details of how you solved the problem so it is useful for other users who experience situations similar to yours. You can mark your own answer as accepted. And then the subject of select could be discussed in a new question.

  • OK Renan I’ll do it Thank you.

  • In this case I understand that the problem is the same, and would fit an issue in the question about select. If new answers appear with a better organization proposal, the separate question becomes obsolete.

Show 3 more comments

1 answer

1


The problem was solved Rafael helped me to think about how would be the logic of the tables that will be related getting like this...

I decided to create two tables that are them campeao_forte and campeao_fraco both have the structure .._principal and .._secundario and on the table campeao_forte in your column .._primario the ID of the champion who is strong will be recorded and in the secondary the ID of the champion who is weak against the primary.

The same occurs in the table campeao_fraco but the primary indicates that the champion is weak against the secondary.

  • Felipe, if possible mark your answer as accepted. :)

  • 2

    I could not accept the answer by clicking accept returns the message "You can accept your reply in 2 days"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.