Following join is supposed to retrieve user info along with their messages for users with a certain status:
SELECT * FROM user, message WHERE message.user_id=user.id AND user.status=1
The problem is that all rows about a certain user in the result set contain redundant columns that repeat the same data about that user (those fields retrieved from user table), only fields from the message table contain non-redundant information. Something like this:
user.id username email message.id subject
1 jane [email protected] 120 Notification
1 jane [email protected] 122 Re:Hello
1 jane [email protected] 125 Quotation
2 john [email protected] 127 Hi jane
2 john [email protected] 128 Fix thiss
2 john [email protected] 129 Ok
3 jim [email protected] 140 Re:Re:Quotation
As you can see many data are redundant and we do not want to first find the users and then go about their messages in loop like structures or something like that. Loops that cause micro-queries should be avoided at all costs.
I am not concerned about the output of my program, that is well handled in the UI. I think perhaps the network traffic produced by returning the result of this query could be substantially reduced if somehow I can manage to eliminate the repetition of user data in all rows pertaining to that user.