jonniejoejonson Posted May 13, 2010 Share Posted May 13, 2010 $sql="SELECT maxTable.maxMessageId, a.*, b.userFirstname, b.userLastname, b.userImage FROM (SELECT MAX(messageId) AS maxMessageId, threadId FROM mail_messages WHERE fromUserId!='".$userId."' GROUP BY threadId) maxTable INNER JOIN mail_messages AS a ON maxTable.maxMessageId=a.messageId INNER JOIN users AS b ON a.fromUserId=b.userId WHERE a.threadId='1' OR a.threadId='2' ORDER BY a.messageId DE SC"; This is hard to explain... but The point is if there is no selection from the subquery where... fromUserId!='".$userId."' i would like to do a differnet subquery instead.. is there a way to do this regards J. Link to comment https://forums.phpfreaks.com/topic/201625-complex-else/ Share on other sites More sharing options...
jskywalker Posted May 15, 2010 Share Posted May 15, 2010 could u extend the sub-query wit a union? ( SELECT * from mail_message WHERE fromUserId!='".$userId."' GROUP BY threadId UNION SELECT ...... ) maxTable But i think it will not get better performance, so i would try to figure out a better way Link to comment https://forums.phpfreaks.com/topic/201625-complex-else/#findComment-1058783 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.