Reuben Gomes Reuben Gomes - 8 months ago 54
MySQL Question

SQL Group by name

I have a table

a | bc
a | dc
a | ef
a | gh
a | ij

I want to create a group by so that it shows

a |bc

I'm currently using

select(*) from 'tablename' group by city;


Not pretty sure if this is what you want, but if you want to get all rows from locality for a in one new cell, you can use this.

SELECT *, GROUP_CONCAT(locality) as localities FROM table GROUP BY city

This will output:

city    localities 
a       bc, dc, ef, gh, ij