Hi!
I have 2 tables. Users and Messages. Messages contains MessageID and Username for this MessageID. Users contains Username and Data. MessageID si unique and Messages.Username is not (there can be many same Username fields in Messages but with different MessageIDs).
I would like to have a SELECT sentence which would produce a Username, Data and number of Messages (this is number of MussageIDs) for a Username which exists in Users and a Username is a Username of a MessageID. I have made this:
SELECT @Username:=Users.Username FROM Users, Messages WHERE Messages.MessageID='given_id' AND Messages.Username=Users.Username;
SELECT Users.Username, Users.Data, COUNT(Messages.MessageID) FROM Users, Messages WHERE Messages.Username=@Username AND Messages.Username=Users.Username GROUP BY Users.Username;
I think that this is an "ugly" solution. Is there a better one?
Mike
I have 2 tables. Users and Messages. Messages contains MessageID and Username for this MessageID. Users contains Username and Data. MessageID si unique and Messages.Username is not (there can be many same Username fields in Messages but with different MessageIDs).
I would like to have a SELECT sentence which would produce a Username, Data and number of Messages (this is number of MussageIDs) for a Username which exists in Users and a Username is a Username of a MessageID. I have made this:
SELECT @Username:=Users.Username FROM Users, Messages WHERE Messages.MessageID='given_id' AND Messages.Username=Users.Username;
SELECT Users.Username, Users.Data, COUNT(Messages.MessageID) FROM Users, Messages WHERE Messages.Username=@Username AND Messages.Username=Users.Username GROUP BY Users.Username;
I think that this is an "ugly" solution. Is there a better one?
Mike