0
Hello! I will explain from the beginning.. I am comparing the following tables accounts
with clientes
select uses the user_id
to find all customers with same users_id2
on the table clientes
as described below, so far so certain!
"SELECT * FROM accounts as a INNER JOIN clientes as c ON (a.user_id=c.users_id2)"
but this gives me this result (repeating user_id)...
[
{
"user_id": "100001",
"email": "[email protected]",
"clientes": {
"id_cliente" => "1",
"users_id": "100001",
"nome_pessoa": "cliente pereira"
}
},
{
"user_id": "100001",
"email": "[email protected]",
"clientes": {
"id_cliente" => "2",
"users_id": "100001",
"nome_pessoa": "cliente Gustavo"
}
}
]
And I need you to return a more precise result by grouping the user_id
and below displaying all the customers listed.. that in json would look exactly like this..
[
{
"user_id": "100001",
"email": "[email protected]",
"clientes": {
"0": {
"id_cliente" => "1",
"users_id": "100001",
"nome_pessoa": "cliente pereira"
},
"1": {
"id_cliente" => "2",
"users_id": "100001",
"nome_pessoa": "cliente Gustavo"
}
}
}
]
So how can I be writing this code in mysql? I tried GROUP BY user_id
but it was unsuccessful..
It worked all right Vinicius , really what I needed Thank you!
– Di Max Developer