I have to update n oldest orders per each user. For now I use following code to update 1 oldest record per user, but can't figure out how to update n records...

```
UPDATE orders
                INNER JOIN (
                    SELECT id, MIN(created) AS created
                    FROM orders 
                    WHERE status="queue" AND type="order"
                    GROUP BY user_id
                ) m ON orders.id = m.id
            SET orders.status = "process",
                orders.lock_id ="somehash"

```

I found anserw:

```
set @num := 0, @type := "";

UPDATE orders INNER JOIN(

SELECT id, user_id, created, row_number FROM (
   SELECT id, user_id, created,
      @num := if(@type = user_id, @num + 1, 1) AS row_number,
      @type := user_id AS dummy
  FROM orders
  WHERE status = "queue"
  ORDER BY user_id, created asc ) AS grouped_orders 
WHERE grouped_orders.row_number <= 2

) m ON orders.id = m.id SET orders.status = "process", orders.lock_id = "somehash";

```