Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 21st, 2012  |  syntax: None  |  size: 0.49 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Initialize a new row in my table (MySql) [closed]
  2. id_customers    order
  3.        1          1
  4.        1          2
  5.        1          3
  6.        2          1
  7.        2          2
  8.        2          3
  9.        3          1
  10.        3          2
  11.        3          3
  12.        
  13. SET @counter = 1;
  14. SET @last = 0;
  15. UPDATE table SET order = (IF(@last = customer_id,@counter + 1,@counter := 1)),
  16.                  @last := customer_id
  17. ORDER BY customer_id
  18.        
  19. SELECT * FROM customers ORDER BY `id_customers` ASC, `order` ASC