Home > database >  Two rows in a single row in mariadb, mysql
Two rows in a single row in mariadb, mysql

Time:10-25

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.

CodePudding user response:

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

CodePudding user response:

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
  • Related