I have the following fields on a SQLite table,
ID - PRODUCT_NAME - PRODUCT_PRICE
1 WCC9899 1023
2 WCC9399 9999
3 WCC93W9 344
4 WCC9819 55
5 WCC3333 1023
This query returns the first item with the highest price:
SELECT max(product_price) as price, product_name, id FROM table
But want to get the item with the highest price ordered by the last id, in this case the result should be:
5 WCC3333 1023
Instead i get:
1 WCC9899 1023
Order by doesn't works, ty.
select *
from your_table
where product_price = (SELECT max(product_price) FROM your_table)
order by id desc
limit 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With