Answer the question
In order to leave comments, you need to log in
Sorting elements from one table based on data in another?
There are 2 tables, one is rooms (rooms), the second is users in the room (usersRoom)
I need to display the rooms based on how many users are in the room in descending order. How to do it?
At least I'll give you an example, I'll figure it out there ;)
Answer the question
In order to leave comments, you need to log in
I would go from this: I don’t have the opportunity to check anywhere now, but it should work:
The idea is this:
SELECT RMS.ID FROM rooms RMS
ORDER BY (SELECT COUNT(Id) FROM usersRoom WHERE roomId = RMS.ID ) DESC
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question