1
I have two tables in my database cad_usuario
and the cad_automovel
. The User registered in the first table may have several vehicles registered in the second table.
SELECT aut.usuario_id, aut.marca, aut.modelo, aut.ano, usr.id, usr.nome_completo, usr.rg FROM cad_automovel as aut INNER JOIN cad_usuario as usr on usr.id = aut.usuario_id
The problem is that when showing the result in PHP, it shows two lines to the same user
----------
id_usuario: 1
nome_completo: John Doe
rg: 000.000.000
aut.usuario_id: 1
aut.marca: marca1
aut.modelo: modelo1
aut.ano: 2017
---------
id_usuario: 1
nome_completo: John Doe
rg: 000.000.000
aut.usuario_id: 1
aut.marca: marca22
aut.modelo: modelo22
aut.ano: 2007
I need it to look something like this:
---------------
id_usuario: 1
nome_completo: John Doe
rg: 000.000.000
aut.usuario_id: 1
aut.marca: marca1, marca22
aut.modelo: modelo1, marca22
aut.ano: 2017, 2007
group_concat does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual
– lkzvieira
@Lucasolivier added an SQL Fiddle demonstrating the correct functioning of query. The function
GROUP_CONCAT
is present in all versions currently maintained for Mysql (5.5 and above). You may have some syntax error just before the function (or be using another database that does not match the one you were asked).– Bacco
really had syntax error. I was able to group the values in the
SQL
. Now I’ll try to show inPHP
, excellent reply! Thank you.– lkzvieira
Lucasolivier was going to comment now, may have been given a space before the (as the colleague @Jeferson mentioned in the network chat. has to be
GROUP_CONCAT(
glued– Bacco