Answer the question
In order to leave comments, you need to log in
COUNT(*) in SQL along with GROUP BY, unexpected result?
Hello.
A little hitch came
out id | text | parent
1 | text | 2
2 | text | 2
3 | text | 3
.
to make sure that parent is not repeated?
I tried GROUP BY parent, but then the problem arose with COUNT (*),
when I do COUNT (*) with GROUP BY,
the result is this:
COUNT(*)
2
3
2
2
2
1
2
2
2
2
2
2
2
2
2
4
id | name | description
id | parent_id | recept_id
id | user_id | parent_id
SELECT r.*, cr.*, uc.*
FROM user_component AS uc
JOIN component_recept AS cr ON cr.parent_id = uc.parent_id
JOIN recept AS r ON r.id = cr.recept_id
WHERE uc.user_id
IN ( 9 )
Answer the question
In order to leave comments, you need to log in
The task is not clear, and you would have attached a request ...
In general, if you need to display parent's and the number of rows for them, then like this:
SELECT parent, COUNT(1)
FROM tbl
GROUP BY parent
.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question