Your query does not select the column o.id
so you can't sort by o.id
.
But it does select and return the column any_value(o.id)
which you can use:
ORDER BY any_value(o.id)
or its alias:
ORDER BY id
Also there is no need to use any_value()
for the column(s) that are included in the GROUP BY
clause:
SELECT o.booking_id, any_value(o.id)id,any_value(u.name) as user_name
FROM orders o
JOIN items ON items.id=o.product_id
JOIN users u ON u.id=o.user_id
JOIN payment p ON p.booking_id=o.booking_id
WHERE o.status =0
GROUP BY o.booking_id
ORDER BY id DESC
LIMIT 10
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…