title: min value of multi column primary key
body: <p>i have three tables like this</p>
  
  <p><code>sales_bill</code> with columns (<code>id</code>, <code>time</code>, <code>user_id</code>, <code>branch_id</code>)</p>
  
  <p><code>sales</code> with columns (<code>id</code>, <code>bill_id</code>, <code>quantity</code>, <code>item_id</code>)</p>
  
  <p><code>sales_plus</code> with columns (<code>sales_id</code>, <code>status</code>, <code>time</code>, <code>branch_id</code>, <code>user_id</code>)</p>
  
  <p>where sales_plus.status is enum('add', 'remove') and one item can be added or removed after the original bill is done and this table primary key is sales_id and status</p>
  
  <p>i need to select the sales with specific bill_id but if the item was added and removed from the bill it shows only removed with its time, branch_id and user_id</p>
  
  <p>here is the best i could do but due to usage of ANY_VALUE it can return the time of the add but with the removed status</p>
  
  <pre><code>SELECT
  bill.id as bill_id,
  bill.user_id as bill_user_id,
  bill.branch_id as bill_branch_id,
  bill.time as bill_time,
  sales.id as sales_id,
  item_id,
  quantity,
  price,
  min(status) AS status,
  ANY_VALUE(sales_plus.user_id) AS sales_plus_user_id,
  ANY_VALUE(sales_.branch_id) AS sales_plus_branch_id,
  ANY_VALUE(sales_.time) AS sales_plus_time,
  FROM sales
  INNER JOIN sales_bill
  ON sales.bill_id = bill.id
  LEFT JOIN sales_plus
  ON sales.id = sales_plus.sales_id
  WHERE bill_id = :bill_id
  GROUP BY sales.id
  </code></pre>