Imran Omar Bukhsh
Imran Omar Bukhsh

Reputation: 8071

Mysql MAX value and Last Record at the same time

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

Answers (2)

juergen d
juergen d

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

DarkAjax
DarkAjax

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

Related Questions