I'm trying to retrieve related values based on multiple entries in the database. I'm very new to MySQL
in terms of using JOINs etc. and I'm trying to avoid involving PHP unnecessarily.
When I say "retrieve nested related values", look at the following example:
1 2 3 4 5 6 7 |
|
If I want to retrieve the greeting of the first person , the process would be:
1 2 3 |
|
Alternatively, if I wanted to retrieve the third person's greeting, it would be changed to:
1 2 3 |
|
So, how do I do this in MySQL? I apologize if this already has an answer; I can't seem to find the wording to research the correct answer.
P粉1869047312024-04-05 11:26:19
1 2 3 4 5 |
|
Recommendation - Make relative column names equal. ie. Not language
and languageId
, but using the same name in both tables (e.g. using languageId
). The same goes for the Greeting and greetingId columns. This will make the query simpler:
1 2 3 4 5 |
|
P粉1945410722024-04-05 00:49:17
JOIN joins records from two tables based on certain conditions. For example if you want to join the records in table "Person" with the records in table "Language" so that the value in column language
is equal to the value in column languageId
you can do this by giving Use the following FROM clause to do this:
1 2 |
|
The result of this JOIN is a table that looks like this
Person.personId | Character.Language | Language.LanguageId | Language.greeting |
---|---|---|---|
1 | one | one | 3 |
2 | Japan | Japan | 1 |
3 | fr | fr | 2 |