group records with the same value as a column

Asked

Viewed 90 times

0

I have a table called shops, this table has: ..., store name and loja_category, example:

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

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

roupas => (
   loja1,
   loja3
),
brinquedos => (
   loja2
)
  • tried the select with group by by store name?

  • Can you give me an example? I used GROUP BY loja_categoria, it only brought a result

  • what language are you using? I think you can receive from mysql and treat (group) by code, not?!

  • I am using PHP if not feasible using SQL...

  • What you want to do is better do via code same.

  • group_concat https://dev.mysql.com/doc/refman/8.0/en/group-by-functions.html#function_group-Concat

  • How would the query, Motta?

Show 2 more comments

1 answer

0

If you are using Mysql from to use the Group By command

SELECT * FROM lojas GROUP BY loja_categoria

Or you can use the distinct command

SELECT DISTINCT nome_categoria, nome_loja FROM lojas
  • returned normal, as if it were a single select

Browser other questions tagged

You are not signed in. Login or sign up in order to post.