i’m writing a chat app with php/mysql
i have 3 tables: user, room and room_participant with these structures:
user: id, username
room: id, title
room_participant: room_id, user_id
Now i want to get list of all rooms along with list of all participants in each room.
Until now i just select all rooms from room table and iterate through all rooms and select users information out of each entry, which is very inefficient.
Is there any way to combine all these select into only 1 select query?
Not certain about this without testing, but give it a try:
To deduplicate rooms, use
GROUP_CONCAT()UPDATE
GROUP_CONCAT()modified to returnid|usernameWith the
userlistgenerated byGROUP_CONCATasid|name,id|name,id|nameyou can use PHPexplode()to separate them.