0

I have a table which keeps the track of user orders . I want to show the user a invoice , hence I need to print the specific column value of last records . How can I do that ?

Mitthun
  • 75
  • 1
  • 8
  • any table structure , sample data and desired output? – Muhammad Raheel Jan 13 '14 at 09:56
  • do you actually mean the last record or all previous records? if the former, perhaps you could use [`mysqli_insert_id()`](http://uk1.php.net/manual/en/mysqli.insert-id.php) – pulsar Jan 13 '14 at 09:58
  • possible duplicate of [Select last row in MySQL](http://stackoverflow.com/questions/4073923/select-last-row-in-mysql) – Huey Jan 13 '14 at 10:04

1 Answers1

0

I'm assuming you have some sort of date or id column to sort the records by so you can identify the last row

SELECT column FROM records ORDER BY id DESC LIMIT 1

In the deplorable event you lack some sort of id to sort the rows by, you can try this in php or some equivalent language:

SELECT COUNT(*) FROM records
//set this as variable x
SELECT column FROM records WHERE 1 LIMIT x-1,1
Huey
  • 5,110
  • 6
  • 32
  • 44