Advertisement
Guest User

Untitled

a guest
Mar 15th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement