Reputation: 8071
If you have table with 2 fields:
ID | AMOUNT
How do you get the max(AMOUNT) and the amount of the last entered record ( order by id desc ) using 1 query ?
Thanking you
Upvotes: 1
Views: 116
Reputation: 204884
select amount as last_amount,
(select max(amount) from your_table) as max_amount
from your_table
order by id desc
limit 1
Upvotes: 1
Reputation: 16223
You can do this:
SELECT
(SELECT MAX(amount) FROM table) as Max,
(SELECT amount FROM table ORDER BY id DESC LIMIT 1) as Last
Upvotes: 0