Answer the question
In order to leave comments, you need to log in
JOIN SQL from 4 tables?
Hello.
I started learning SQL in detail only recently.
And then he stumbled, how to pull information from tables (more than 2)?
For example, there is a table:
1. Recipe : id | name | description | ...
2. Recipe components : id | recept_id | parent_id | ...
recept_id -> recipe id from table 1, parent_id -> component id from table
3 3. Componentsid | name | percent | ...
4. Flavors : id | taste | recept_id
recept_id -> recipe id from table 1
Need to get:
1. All information from the recipe,
2. Information about the component (which is used in this recipe)
2. Flavors used in this recipe
Please tell me how it will look like, I'm not very friendly with JOIN yet, I only know how to pull it out of 2 tables and no more, I will be very grateful.
Thanks to all :)
Answer the question
In order to leave comments, you need to log in
I'm from the MS SQL world, so some inconsistencies are possible:
SELECT rcp.*, cmp.*, tst.*
FROM recept AS rcp
INNER JOIN recept_component AS rcp_cmp ON rcp.id = rcp_cmp.recept_id
INNER JOIN component AS cmp ON cmp.id = rcp_cmp.parent_id
INNER JOIN taste AS tst ON tst.recept_id = rcp.id
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question