如何 select 具有相同唯一外国 ID 的最新记录?
How to select latest record with same unique foreign id?
嗨,我想 select 使用 task_id 作为外键 status 的记录,
我想在基于 Phpfox 的查询中使用它,但如果可以解决请告诉我此 scnario
的一般查询
id task_id status
--------------------------
1 2 1
2 3 3
3 2 3
4 2 2 <------- select this record
5 4 1
这是你想要的吗? task_id = 2
具有最后更新状态(或者我可以说最后插入 table):
SELECT * FROM tbl_name WHERE task_id = 2 ORDER BY id DESC LIMIT 1
嗨,我想 select 使用 task_id 作为外键 status 的记录, 我想在基于 Phpfox 的查询中使用它,但如果可以解决请告诉我此 scnario
的一般查询id task_id status
--------------------------
1 2 1
2 3 3
3 2 3
4 2 2 <------- select this record
5 4 1
这是你想要的吗? task_id = 2
具有最后更新状态(或者我可以说最后插入 table):
SELECT * FROM tbl_name WHERE task_id = 2 ORDER BY id DESC LIMIT 1