mysql - Get a subset of rows grouping by one of them -


i working on ecommerce site products, products variants, etc. have made complex query throws following results.

 id | product_id | options  ----+------------+---------   1 |          1 | 1   2 |          1 | 1   3 |          1 | 1   4 |          1 | 2   5 |          1 | 2   6 |          1 | 3   7 |          1 | 3   8 |          1 | 1   9 |          1 | 4 

what need do, selecting first record each different option value. in last example need write select statement return following rows:

 id | product_id | options  ----+------------+---------   1 |          1 | 1   4 |          1 | 2   6 |          1 | 3   9 |          1 | 4      select distinct (options,product_id) , id from(       <the query returns rows on question>   ) prodvalues group product_id, options; 

but no luck that. stucked. help? thanks!

your query looks should work. product want?

select options, product_id, max(id) id (       <the query returns rows on question>      ) prodvalues group product_id, options; 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -