Let's say I have a table like below:
id user_id name custom_field status
1 123 lee firstname 1
2 123 tan lastname 1
3 123 chan firstname 1
4 123 jackie lastname 1
5 123 justin firstname 0
6 123 wong lastname 0
7 223 kevin firstname 1
8 223 riley lastname 1
9 223 john firtname 1
10 223 poh lastname 1
What i want to do is, foreach user_id i want to make sure there is only status 1 for 1 firstname and 1 lastname. (so basically i want to order by the id desc and update status 1 to 0 for those that are not in the top 2). What sql script should i use to accomplish this?