Is it real to select data from multiple tables with INNER JOIN
and put it in array field?
For example i have tables users, user_details, user_clients
Table users
have next columns: [id, login, password]
Table user_details
have: [first_name, last_name, profile_pic, fk_userID]
And table user_clients
contains information about all clients which belong to this user: [client_name, client_phone, client_address, fk_userID]
One user can have many clients from user_clients
.
So i can get this data by next SQL queryes:
$userGeneralData = $db->query("SELECT * FROM users INNER JOIN user_details ON(users.id = user_details) WHERE users.id = 13");
and immediately query to get user clients into array
$arrUserClients = $db->query("SELECT * FROM user_clients WHERE fk_userID=13");
But can i do the same, with only one query? To get clean output without duplication and with array field of user_clients
?
If i'll use typical INNER JOIN
for user_clients i would get duplication data, something like this:
[0] => Array
(
[id] => 13
[login] => rob
[password] => 123
[first_name] => Robert
[last_name] => Frido
[profile_pic] => picture_1.png
[client_name] => Andrew
[client_phone] => +371 13243
[client_address] => Some street 1
[fk_userID] => 13
)
[1] => Array
(
[id] => 13
[login] => rob
[password] => 123
[first_name] => Robert
[last_name] => Frido
[profile_pic] => picture_1.png
[client_name] => Martin
[client_phone] => +422 1423423
[client_address] => London
[fk_userID] => 13
)
So, main information about user duplicates in each array, and changed only client information.
I wanted to put all information about client, into field as array, something like this (i dont sure that it's real to do):
Array
(
[id] => 13
[login] => rob
[password] => 123
[first_name] => Robert
[last_name] => Frido
[profile_pic] => picture_1.png
[arr_clients] =>
[0] => Array (
[client_name] => Anrew
[client_phone] => +371 13243
[client_address] => Some street 1
[fk_userID] => 13
)
[1] => Array (
[client_name] => Martin
[client_phone] => +422 1423423
[client_address] => London
[fk_userID] => 13
)
)