Answer the question
In order to leave comments, you need to log in
How to make MySql select from multiple tables?
Hello.
There is such a scheme of tables:
Need:
Make a query in such a way as to select all records from the Resources table with values from the Variable_values table.
The result should look something like this:
resource
----id
----title
----variables
--------variable
------------id
------------title
------------values
----------------value
----------------value
----------------value
--------variable
------------id
------------title
------------values
----------------value
----------------value
----------------value
--------variable
------------id
------------title
------------values
----------------value
----------------value
----------------value
----childs
--------resource
------------id
------------title
------------variables
----------------variable
--------------------id
--------------------title
--------------------values
------------------------value
------------------------value
------------------------value
------------childs
и т.д.
SELECT * FROM Resources AS Models
LEFT JOIN Resources AS Designs ON Designs.parent_id = Models.id
LEFT JOIN Resources AS Batches ON Batches.parent_id = Designs.id
WHERE Designs.template_id = id шаблона дизайна модели
AND WHERE Batches.template_id = id шаблона серии дизайна
Answer the question
In order to leave comments, you need to log in
SELECT * FROM Resources AS Models
LEFT JOIN Resources AS Designs ON (Designs.parent_id = Models.id AND Designs.template_id = id шаблона дизайна модели)
LEFT JOIN Resources AS Batches ON (Batches.parent_id = Designs.id AND Batches.template_id = id шаблона серии дизайна)
WHERE Models.parent_id IS NULL
AND Designs.id IS NOT NULL
AND Batches.id IS NOT NULL
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question