php - Get related rows in one table using a table with relations -
i have 2 tables. 1 stores content records, other 1 stores relations between content-records.
table "content" table "relations" +---+-----+------+------+ +---------+----------+ |id |num |text |value | |id_local |id_foreign| +---+-----+------+------+ +---------+----------+ |1 |111 |aaa |12345 | |2 |3 | +---+-----+------+------+ +---------+----------+ |2 |222 |bbb |23456 | |2 |5 | +---+-----+------+------+ +---------+----------+ |3 |333 |ccc |34567 | |4 |1 | +---+-----+------+------+ +---------+----------+ |4 |444 |ddd |45678 | |2 |1 | +---+-----+------+------+ +---------+----------+ |5 |555 |eee |56789 | |3 |6 | +---+-----+------+------+ +---------+----------+ |6 |666 |fff |67890 | |4 |5 | +---+-----+------+------+ +---------+----------+
reading table "relations"
id_local = id of record in content ("parent")
id_foreign = id of record in content related id_local ("child")
i want relations content.num = 222 in order entered in table "relations". result should this:
result +-----+------+ |num |value | +-----+------+ |333 |34567 | +-----+------+ |555 |56789 | +-----+------+ |111 |12345 | +-----+------+
i tried joins never got result.
please, know how can result?
additional question:
if want output content.value=23456 of "parent"-record "child"-records, how should query like?
result 2 +-----+------+--------+ |num |value | p-value| +-----+------+--------+ |333 |34567 | 23456 | +-----+------+--------+ |555 |56789 | 23456 | +-----+------+--------+ |111 |12345 | 23456 | +-----+------+--------+
i guess weird method but;
select num, value content id in ( select id_foreign relations id_local = ( select id content num = '222' ) ) , num = '222' -- additional answer
Geometric Transformation OpenCV Python
ReplyDeleteOpenCV Specific Color Detection from Capture Video
Python OpenCV Detect Specific Color
Python Matplotlib Scatter Plot
Simple Matplotlib Animation Example