Answer the question
In order to leave comments, you need to log in
How to make a sql fetch correctly?
Good day, there are 2 tables "category" (id_category, id_parent) and "cat_info" (id_category, name)
how to correctly select that there was a list of all existing categories with the name and also with the name of the parent category
id_category | category_name | parent_category_name |
Answer the question
In order to leave comments, you need to log in
SELECT c.id_category as id, n.name as name, p.name as parent_name
FROM category as c
LEFT JOIN cat_info as n USING(id_category)
LEFT JOIN cat_info as p ON c.id_parent = p.id_category
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question