1

I want to select the last saved record of a user from a table.Sometimes each user can have a duplicate uid which is the main search criteria but each record has a different id and date-time. If i select it using this

  SELECT * from recharges WHERE uid = '$uid' LIMIT 1

it returns the first record of the user as oppose to what i want it to retrieve.

Emmyz
  • 25
  • 4

1 Answers1

0

You will need to sort the order in descending order by id (Assuming it to be your PK, where higher id value means latest entry)

SELECT * FROM recharges 
WHERE uid = '$uid' 
ORDER BY id DESC 
LIMIT 1
Madhur Bhaiya
  • 28,155
  • 10
  • 49
  • 57