1

This is the table:

            name | id | 
            --------------------
            jim  | 267
            jill | 267
            larry| 268
            tim  | 269 
            riley| 267
            joe  | 301
            pete | 301
            gil  | 110
            shay : 701
            bill | 301              

The desired result is separate into 5 categories, different numbers should be scattered across the categories while keeping same numbers together:

            cat 1    | cat 2    | cat 3  | cat 4   | cat 5
            ------------------------------------------------
            jim 267  |Larry 268 |joe 301 |gil 110  |shay 701
            jill 267 |tim 269   |pete 301|         |
            riley 267|          |bill 301|         |

So essentially I want to grouping like while separating different id's as much as possible.

Kalamarico
  • 5,466
  • 22
  • 53
  • 70
Bill Stig
  • 23
  • 4

1 Answers1

0

It looks you want grouping name and id wise. If so then it should be simple just make sure while grouping reverse the order

Select name,id from table group by id,name
A Singh
  • 9
  • 4
  • yes, thats on the right track but results needs to be counted and ordered by most to least matches, this sorts but doesnt arrange. – Bill Stig Apr 24 '18 at 16:45
  • Do you wish to arrange horizontally ? – A Singh Apr 24 '18 at 16:55
  • yes, the ultimate goal is to arrange these in most matches to least matches. so most matches in one column to least in last column. I havbe had some success in test with count( * ) and having, even a php loop stepping through, but still a bit confused on how to achieve this – Bill Stig Apr 24 '18 at 18:00