Didn't know how to correctly write a question in Title, but I will try to explain what I am trying to achieve.
These are my parent tables:
hgs_meaning hgs_word_types hgs_transliterations
+----+---------+ +----+-----------+ +----+-----------------+
| id | meaning | | id | word_type | | id | transliteration |
+----+---------+ +----+-----------+ +----+-----------------+
| 3 | man | | 4 | noun | | 5 | mnjw |
+----+---------+ +----+-----------+ +----+-----------------+
These are my junctional tables:
junc_meaning_word_type
+----+------------+--------------+
| id | meaning_id | word_type_id |
+----+------------+--------------+
| 2 | 3 | 4 |
+----+------------+--------------+
junc_transliteration_meaning_word_type
+----+--------------------+----------------------+
| id | transliteration_id | meaning_word_type_id |
+----+--------------------+----------------------+
| 1 | 5 | 2 |
+----+--------------------+----------------------+
I know how to make SELECT JOIN
query to get results for junc_meaning_word_type
table but not for junc_transliteration_meaning_word_type
I know how to get this result:
+----+-----------------+-------------------+
| id | transliteration | meaning_word_type |
+----+-----------------+-------------------+
| 1 | mnjw | 2 |
+----+-----------------+-------------------+
I am trying to achieve this result:
+----+--------------------+------------+--------------+
| id | transliteration_id | meaning_id | word_type_id |
+----+--------------------+------------+--------------+
| 1 | mnjw | man | noun |
+----+--------------------+------------+--------------+
How this can be done. I am guessing that I need to use nested SELECT
queries (subqueries) or multiple JOIN
s, but I don't know how to construct such a query.
Here are my queries:
/* hgs_meanings and hgs_word_types join to junc_meaning_word_type */
SELECT junc_meaning_word_type.id, hgs_word_types.word_type, hgs_meanings.meaning
FROM junc_meaning_word_type
JOIN hgs_word_types ON junc_meaning_word_type.word_type_id = hgs_word_types.id
JOIN hgs_meanings ON junc_meaning_word_type.meaning_id = hgs_meanings.id
/* hgs_transliterations and junc_meaning_word_type join to junc_transliteration_meaning */
SELECT junc_transliteration_meaning.id, hgs_transliterations.transliteration, junc_meaning_word_type.id
FROM junc_transliteration_meaning
JOIN hgs_transliterations ON junc_transliteration_meaning.transliteration_id = hgs_transliterations.id
JOIN junc_meaning_word_type ON junc_transliteration_meaning.meaning_word_type_id = junc_meaning_word_type.id
Any help would be appreciated.