Sometime we required last insert value just assign order wise your fetching query. below i write some useful way fetching database records.
Last Record in database
This query show your table last insert valueSELECT * FROM table_name ORDER BY column_id DESC;
First Record
This query show your table First insert valueSELECT * FROM table_name ORDER BY column_id ASC;
Limit
This query show your table limited recordsSELECT * FROM table_name LIMIT 5;
2nd value record
SELECT * FROM table_name LIMIT 2,1;
find the second largest value
SELECT MAX(colum)FROM table WHERE col < ( SELECT MAX( colum ) FROM table );
Oreder by date
SELECT * FROM table_name ORDER BY DATE(updated_at) DESC
No comments:
Post a Comment