JohnOP Posted January 13, 2012 Share Posted January 13, 2012 I'm re doing my private message system and im watching a video tutorial on it but have got this very strange error with the max() function code <?php $sql = "SELECT `conversations`,`conversation_id`, `conversations`,`conversation_subject`, MAX(`conversations_messages`,`message_date`) AS `conversation_last_reply` FROM `conversations` LEFT JOIN `conversations_messages` ON `conversations`,`conversation_id` = `conversations_messages`,`conversation_id` INNER JOIN `conversations_members` ON `conversations`,`conversation_id` = `conversations_members`,`conversation_id` WHERE `conversations_members`,`user_id` = {$id} AND `conversations_members`,`conversation_deleted` = 0 GROUP BY `conversations`,`conversation_id` ORDER BY `conversation_last_reply` DESC"; All the fields and tables are correct and i get this error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`message_date`) AS `conversation_last_reply` FROM `conversations` LEFT J' at line 3 Link to comment https://forums.phpfreaks.com/topic/254952-max-error-why/ Share on other sites More sharing options...
mikosiko Posted January 13, 2012 Share Posted January 13, 2012 and when everything fail then is time to go back to the basic source of information http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_max Link to comment https://forums.phpfreaks.com/topic/254952-max-error-why/#findComment-1307228 Share on other sites More sharing options...
kickstart Posted January 13, 2012 Share Posted January 13, 2012 Hi Max shouldn't have 2 columns in it. All the best Keith Link to comment https://forums.phpfreaks.com/topic/254952-max-error-why/#findComment-1307235 Share on other sites More sharing options...
JohnOP Posted January 13, 2012 Author Share Posted January 13, 2012 It doesn't one is the table name and one is the column from that table. Link to comment https://forums.phpfreaks.com/topic/254952-max-error-why/#findComment-1307236 Share on other sites More sharing options...
kickstart Posted January 13, 2012 Share Posted January 13, 2012 Hi Separate them with full stops. You might as well remove all the back tics as well (only needed when the column names are reserved words, and best to avoid that anyway) All the best Keith Link to comment https://forums.phpfreaks.com/topic/254952-max-error-why/#findComment-1307242 Share on other sites More sharing options...
mikosiko Posted January 13, 2012 Share Posted January 13, 2012 the fact that you are using , instead of a dot to separate table name from column names is what is causing that error... and you have the same mistake in all others fields in your select Link to comment https://forums.phpfreaks.com/topic/254952-max-error-why/#findComment-1307244 Share on other sites More sharing options...
JohnOP Posted January 13, 2012 Author Share Posted January 13, 2012 Oh its a dot and not a comma, thanks a lot that worked. Link to comment https://forums.phpfreaks.com/topic/254952-max-error-why/#findComment-1307249 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.