Order
MySQL Statement: Order
Categories:
Order by random
ORDER BY rand();
Order by select column
SELECT
*
FROM `users`
WHERE `users`.`id` IN (11, 22)
ORDER BY (
SELECT `created`
FROM `orders`
WHERE `user_id` = `users`.`id`
ORDER BY `created_at` DESC
LIMIT 1
) ASC
Select latest order field
SELECT
`users`.*
,(
SELECT `order_id`
FROM `orders`
WHERE `user_id` = `users`.`id`
ORDER BY `created_at` DESC
LIMIT 1
) AS `latest_order`
FROM `users`
WHERE `users`.`id` IN (11, 22)