I
I
Ilya Kochkin2015-08-16 08:53:52
SQL
Ilya Kochkin, 2015-08-16 08:53:52

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

1 answer(s)
A
Alexey Ukolov, 2015-08-16
@mr_Koch

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

Documentation .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question