Hello! I will explain from the beginning .. I am comparing the following tables accounts
with clientes
select uses user_id
to find all clients with same users_id2
in table clientes
as described below, right there!
"SELECT * FROM accounts as a INNER JOIN clientes as c ON (a.user_id=c.users_id2)"
But this a returns this result (repeating the 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"
}
}
]
I need to return a more accurate result by grouping the user_id
and below showing all the clients listed .. which 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've tried GROUP BY user_id
but it was unsuccessful ..