skip to Main Content

let’s say i have this

id center right
1 Two NULL
1 NULL Three

and want to be like this

id center right
1 Two Three

my first table is just a representation of what actually I am encountering, everything will be appreciated, thank you in advance.

2

Answers


  1. You can group by the id column and the the max values of the other records

    select id, 
           max(center) as center, 
           max(`right`) as `right`
    from your_table
    group by id
    
    Login or Signup to reply.
  2. You can group by id and group_concat the columns like this

    SELECT id, group_concat(`center`) as center, group_concat(`right`) as rights FROM `your_table` group by id;
    

    https://www.db-fiddle.com/f/9phZ7EpRUS4FNRBZRdSYZa/116

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search