L
L
Lite_robot2015-11-17 21:43:57
MySQL
Lite_robot, 2015-11-17 21:43:57

SQL: how to organize the dependency of elements that are in the same table?

Good day, Toaster. There is a certain table with disciplines, to study these disciplines you need to study other disciplines from the same table. How to organize a table of dependencies with these disciplines?
simple table:
id, name

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Max, 2015-11-17
@Lite_robot

make a dependency table.
who, from whom

N
nozzy, 2015-11-18
@nozzy

id, parent_id, name
in parent_id write the id of the discipline you want to study.

D
DDDsa, 2015-11-18
@DDDsa

An additional dependency table is not the most elegant solution. It will be much more beautiful to create a hierarchy.
Remember how all the SQL textbooks give as an example a table of employees indicating which of them is whose manager?
And here is another link to the topic: Hierarchical (recursive) queries , they tell you how to deal with such tables

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question