I’m just stuck with a simple mysql query, I want to update the row having max Id of a table, and I was trying something like but it doesn’t work
UPDATE inbox i
INNER JOIN messages m ON i.message_id = m.id
SET i.read = 0
WHERE m.conversation_id = 10
AND i.user_id = 1
ORDER BY i.id DESC
LIMIT 1
I’ve also tried sub query but it doesn’t work either
Need some help on it.
Thanks
In MySql you can’t update a table if you have a subquery that references the same table, but you could sostitute the subquery with JOINS. I would do this, it’s a trick but it works:
EDIT: I see you edited your question, so i have to edit my answer:
Your subquery returns the maximum id based on the
conversation_idand theuser_idyou want, then you joininboxwhith the maximum id to select just the row you want, and you can then update just that row.