Good afternoon!
I have this SQL query:
SELECT u.id, u.avatar, u.city, u.f_name, u.s_name, u.notes, u.username, SUM(b.summ) AS summ FROM users AS u LEFT JOIN balance AS b ON b.user_id = u.id WHERE $conditions GROUP BY u.id ORDER BY summ DESC;
As you can see, there is a sorting by the summ field, but I also need to sort by the fields, for example, two users:
- Ivan Savkov NULL NULL 5000
- Kostya Malikov Moscow 1 5000
As you can see, both are 5,000 each, but Ivan is the first on the list, and I need the second one, because not all of his fields are filled out.
Here is such a task, thanks)