SHARE
TWEET

Untitled

a guest Mar 15th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. id       PRODUCT ID    COLOUR
  2. 1        1001          GREEN
  3. 2        1002          GREEN
  4. 3        1002          RED
  5. 4        1003          RED
  6.    
  7. SELECT *
  8. FROM yourtable
  9. WHERE ProductID = (your id)
  10. ORDER BY colour
  11. LIMIT 1
  12.    
  13. select yourtable.*
  14. from
  15.     yourtable
  16.     inner join
  17.     (select productid, min(colour) mincolour
  18.     from yourtable
  19.     where productid like '10%'
  20.     group by productid) v
  21.     on yourtable.productid=v.productid
  22.     and yourtable.colour=v.mincolour
  23.    
  24. SELECT top 1 *
  25. FROM <table>
  26. WHERE ProductID = <id>
  27. ORDER BY case when colour ='GREEN' then 1
  28.               when colour ='RED' then 2 end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top