Answer the question
In order to leave comments, you need to log in
How to make a selection from three tables in SQL?
I can not understand how to make a request to select three fields from three different tables of the same database.
In the attachment of a screenshot of the tables, you need to make a selection and show the names of goods, the names of subcategories and the names of categories.
Can you please tell me how to make a request?
Answer the question
In order to leave comments, you need to log in
select
t1.name_goods,
t2.name_subcat,
t3.name_cat
from goods t1
left join subcategory t2 on t2.id_subcat = t1.id_subcat
left join category t3 on t3.id_cat = t1.id_cat
You have an indeterminacy: in category
no subcategory
for id_subcat (110, 111)
.
In goods
trimmed id_cat
or not divided into subcategories.
And it is possible without correction:
SELECT goods.name_goods, subcategory.name_subcat, category.name_cat
FROM goods
LEFT OUTER JOIN category ON goods.id_cat = category.id
LEFT OUTER JOIN subcategory ON goods.id_cat = subcategory.id_subcat / 10
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question