问题描述:

I union join two columns where i get records of [email protected] avaiable in two in columns. which that works perfectly. But what i want to achieve is when a particular user "[email protected]" is logged on, on click on user [email protected], he should be able to see the messages sent to him by [email protected], also when [email protected] should logged in he too must be able to see message sent to him by [email protected]

because when i execute i seem to get all the messages [email protected] has sent to every users in the table.

how do i join these fields to make it work

 SELECT *

FROM dbo.IM

INNER JOIN profile ON im.sid = profile.profile_id

WHERE sid = '3'

AND im_sender = '[email protected]'

UNION

SELECT *

FROM dbo.IM

INNER JOIN profile ON im.sid = profile.profile_id

WHERE rid = '2'

AND im_reciever = '[email protected]'

ORDER BY id ASC

i'm using an image below to explain. i want to only return records sent by the logged in user [email protected] to cgblay....., but as you see records of also [email protected] is also found

网友答案:

Not quite sure about your problem. Seems you are after this

SELECT *
FROM   dbo.IM
        INNER JOIN profile ON im.sid = profile.profile_id
WHERE  sid = '3'
       AND im_sender = '[email protected]'
       and rid = '2'
       AND im_reciever = '[email protected]'
相关阅读:
Top