Search code examples
phpmysqlphpfox

How to select latest record with same unique foreign id?


Hi i want to select the record with latest updated status using task_id as foreign key, I want this in Phpfox based query, but if can solve let me know the general query for this scnario

id     task_id   status
--------------------------
 1       2           1
 2       3           3
 3       2           3
 4       2           2  <------- select this record
 5       4           1

Solution

  • Is this what you want? task_id = 2 with last updated status(or I can say last inserted in table):

    SELECT * FROM tbl_name WHERE task_id = 2 ORDER BY id DESC LIMIT 1