group records with the same value as a column

0

I have a table called stores , this table has: ..., store_name and store_category, example:

nome_loja | loja_categoria
--------------------------
    loja1 | roupas
    loja2 | brinquedos
    loja3 | roupas

What I would like to do is to group the records with the same category name, case insensitive if possible, with the result being an associative array with the name of the categories, something like this:

roupas => (
   loja1,
   loja3
),
brinquedos => (
   loja2
)
    
asked by anonymous 11.05.2018 / 19:37

1 answer

0

If you are using Mysql from to use the Group By

SELECT * FROM lojas GROUP BY loja_categoria

Or you can use the distinct

SELECT DISTINCT nome_categoria, nome_loja FROM lojas
    
11.05.2018 / 22:26