I am writing an online chat and I have two objects, a chat room and a chat user. 1 chat room can contain many chat users.
SELECT Chatrooms.created_dt,
Chatrooms.description,
ChatUser.first_name,
ChatUser.last_name,
ChatUser.email
FROM Chatrooms
LEFT JOIN ChatUser
ON ChatUser.room_id = Chatrooms.id
WHERE Chatroom.status = 1
this will provide me with rows like
2011-09-08 , I need serious help , daffy, duck, daffy@loony.com
2011-09-08 , I need serious help , donald, duck, donjuan@disney.com
2011-09-08 , I need serious help , darkwing, duck, darkcape@aol.com
Obviously I would like to avoid duplicating the chat room information every row. However, I would also like to avoid running multiple queries. I only have basic experience with dbs and as mysql doesn’t have foriegn keys (not sure how that would even help me), I am not sure what better options are.
Is there something better I can do in this situation, or just not worry about the duplicate columns?
As far as I know, I don’t believe there is a way to select the information that you’re trying to achieve without either running two queries or having some of the information duplicated.
I mean essentially what you’re doing is asking the database to fetch you information about the chat room AND chat users in the same query… and unless you could find a way to write that out on a piece of paper using the same columns and data types for every row, it probably isn’t possible.
So having that said, you probably could just ignore the duplicate data in every row to accomplish your goal.