I have the following tables:
users
id
| name
info
id | info | user_id
(user_id from table info is foreign key => connects to id from table users)
It is possible that the user will have many entries in the info table (same user_id in many rows).
Now I want to fetch data and display it like that:
username:
... info ....
Example:
admin:
aaa
bbb
ccc
someuser:
ddd
eee
fff
So I use LEFT JOIN like that:
SELECT users.name, info.info
FROM users
LEFT JOIN info
ON users.id = info.user_id
But what I get is the following:
admin:
aaa
admin:
bbb
admin:
ccc
How can i display the username only once? I've tried using DISTINCT
keyword after SELECT
but it didn't help. Meanwhile i solve this problem inside the php code itself, but is there any way to fix this only inside the sql?