I keep getting this statement “Invalid use of group function”
for this query
mysql_query("UPDATE users SET users.lastmessage = MAX(messages.id) WHERE users.name ='tom'")
or die(mysql_error());
What I’m trying to do is take the lastmessage field in the users table and update it to be the largest id in the messages table where the name = tom
What did I do incorrectly
You want to execute a sub-query to get the maximum Id for the user ‘tom’ which is done as follows:
Edit: WHERE clause to only perform this for the correct user