Get the list ordered by how many times it appears in another table
I am using mysql and doctrine2.
I have two tables like these below
User.php
ID name
1 | John
2 | Jonas
3 | Nick
Class.php
ID attenduser
1 | 3
2 | 3
3 | 1
4 | 1
5 | 3
6 | 2
Class.attenduser is constraint with User.ID
it means Nick attends class three times. John two times and Jonas one time.
For now I get user list by this doctrine sql
SELECT p FROM UserBundle:User p
However,I want to get the user list ordered by how many times he attend
the class.
How should I change this?
No comments:
Post a Comment