How to get last 3 values from Mysql table
-
hi, am adding new record for every transaction,then how to get the last 3 transaction values.
-
hi, am adding new record for every transaction,then how to get the last 3 transaction values.
It would be best to have a TIMESTAMP column that defaults to CURRENT_TIMESTAMP .. it is the only true predictive behavior you can find here.
The second-best thing you can do is ORDER BY ID DESC LIMIT 1 and hope the newest ID is the largest value.
check this also accessing-last-inserted-row-in-mysql[^] Hope it will help..
-
It would be best to have a TIMESTAMP column that defaults to CURRENT_TIMESTAMP .. it is the only true predictive behavior you can find here.
The second-best thing you can do is ORDER BY ID DESC LIMIT 1 and hope the newest ID is the largest value.
check this also accessing-last-inserted-row-in-mysql[^] Hope it will help..
Not only one record. there exist duplicates(Means no primary key) get the last inserted 3 records for the same id
-
hi, am adding new record for every transaction,then how to get the last 3 transaction values.
Member 10263519 wrote:
am adding new record for every transaction,then how to get the last 3 transaction values
You can't get them at transaction-level, as they don't exist at that level. A transaction can touch multiple tables, so those 3 "last values" might be all in different tables (or in the same record). If you're trying to write an audit, look into triggers.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]