グループ内の単一の行を更新する MySQL 用の SQL ステートメントを作成しようとしています。以下のレコードを取得すると、IsPrimary フラグを更新して、各ユーザーの最も古いレコードが 1 に設定されるようにする必要があります。
ID | UserID | Inserted | IsPrimary
----------|-------------|-------------|----------
000f83 | 79b8c3 | 2012-03-14 | 0
001401 | 79b8c3 | 2012-03-15 | 0
002e7d | 4652a2 | 2012-02-22 | 0
003ca6 | 4652a2 | 2012-02-13 | 0
したがって、上記のレコードは次のようになります。
ID | UserID | Inserted | IsPrimary
----------|-------------|-------------|----------
000f83 | 79b8c3 | 2012-03-14 | 1
001401 | 79b8c3 | 2012-03-15 | 0
002e7d | 4652a2 | 2012-02-22 | 0
003ca6 | 4652a2 | 2012-02-13 | 1