Suppose there are two tables. First table, ‘user_actions’, has two fields: ‘user_id’ and ‘action’. Second table, ‘users’, also has two fields: ‘id’ and ‘name’. I want to sort the first table so that actions commited by users Aaron or Bruce go first and actions commited by Yuriy and Zorro go last. How would I do that?
I tried this:
select * from `user_actions` order by field(`user_id`,(select distinct `id` from `users` order by `name`))
Doesn’t work.
Why the subquery and not a join?
Something like this: