This is a sample from the base according to the conditions: Source array:

0 : { group: "1", value: "4"} 1 : { group: "1", value: "4"} 2 : { group: "1", value: "8"} 3 : { group: "2", value: "2"} 4 : { group: "2", value: "8"} 5 : { group: "2", value: "8"} 

The question is, is it possible to group the elements with the MySql query, provided that only the value elements from their group can be grouped?

The final grouping variant should be such an array:

 0 : { group: "1", value: "4"} 2 : { group: "1", value: "8"} 3 : { group: "2", value: "2"} 4 : { group: "2", value: "8"} 
  • Can. Show the original request. - Anton Shchyrov
  • Inside the group we write case when .... then .... else ... end . They can be put one-on-one (tree), - and make a conditional group of any complexity. - nick_n_a
  • It sounds cool. Can I have a little example? - Typography manager
  • 2
    select distinct group, value from table . Or, if the number that is in front of the parentheses is the same in the database and is needed, then an elementary group by in these two fields, and then the field in front of the parentheses, for example min () - Mike
  • select distinct group, value - works. Read the documentation on it. It seems everything is simple and logical, but I do not understand exactly how distinct it works. Let's say if he chooses a unique group, then why he did not show 2 entries, and 4 as needed. - Typography Manager

0