Skip to content
Advertisement

Tag: sql-order-by

Sort by given “rank” of column values

I have a table like this (unsorted): risk category Low A Medium B High C Medium A Low B High A Low C Low E Low D High B I need to sort rows by category, but first based on the value of risk. The desired result should look like this (sorted): risk category Low A Low B Low C

Select the row with the most recent modified date

I have this table: user_id name email modified_date 1 John a@gmail.com 2022-01-01 1 John b@gmail.com 2022-01-02 1 Lucy c@gmail.com 2022-01-03 2 Joey d@gmail.com 2021-12-24 3 Mike e@gmail.com 2022-01-01 3 Mary f@gmail.com 2022-01-02 I’m trying to get unique user_id’s email with the most recent modified_date. This is my expected output: user_id email name 1 c@gmail.com Lucy 2 d@gmail.com Joey 3 f@gmail.com

SQL – Ordering table with subquery for select

I am trying to do ordering on query with subquery for a name from uuid. Let’s have those two tables in MySQL: bans: id uuid time reason 1 c6b8eade-7db9-345b-b838-8f8361552cf5 1642369382 Test 2 0138c279-c5fa-3acd-adaa-8edb7b4569d8 1642384565 Spam 3 3c01262c-a3c3-3133-ba43-92a9ded01c27 1631876477 Hax users: id uuid name 45 c6b8eade-7db9-345b-b838-8f8361552cf5 John 100 0138c279-c5fa-3acd-adaa-8edb7b4569d8 Mike 35 3c01262c-a3c3-3133-ba43-92a9ded01c27 Norman With this query, I can select whole ban

Advertisement