Jump to content

complex else


jonniejoejonson

Recommended Posts

$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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.