Answer the question
In order to leave comments, you need to log in
How to display parent records from a database that has child mysql records?
There is a Questions table with fields ( id, question, parent_id, type )
C entries
id | question | parent_id | type
1 | first question parent? | 0 | parent
2 | first question child? | 1 | input
3 | second parent ques? | 0 | parent
4 | second question child ? | 1 | input
How can I display parent queries that have children
Sometimes parent queries do not have child questions and these parent queries do not need to be displayed
Wrote a query that should display the first question (id = 1) because it has 2 child questions
select * from `questions` as `ques` where `ques`.`id` = `parent_id` // вернет пустоту
select count(*) from `questions` as `ques` where `ques`.`id` = `parent_id` // вернет 0 должно было 2
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question