2uzhan.com
Advertisement
Now Place:2uzhan.com » Can someone please help me with a SELECT ???

Can someone please help me with a SELECT ???

MySQL @ January 8, 2012   Views:0

Hey :-)

I have a problem with a SELECT and really don't know how i can realize that.
I have the following situation:

----------------------
| SEND | RECEIVE |
|---------------------
| A | B |
| B | A |
|---------------------

I need a SELECT where i can ask "if SEND = A THEN $x = RECEIVE / IF RECEIVE = A THEN $x = SEND. MY result should be just "B".

I tried the following:
SELECT SEND FROM sk_message WHERE RECEIVE = '$von' GROUP BY SEND ORDER BY SEND ASC
I really dont' know how to involve both. I need this for a little shoutbox. A user is looged on but should be the sender or receiver.
I hope you can understand me.

Thank you

--------------Solutions-------------

Your logic is incomplete: what if receive <> A? Assuming that answer is `receive`:

select distinct if(send='A',receive,if(receive='A',send,receive)) from tbl;

PB Thank you :-) Another approach:
SELECT send FROM tbl WHERE receive = 'A'
UNION DISTINCT
SELECT receive FROM tbl WHERE send = 'A'

In either solution, it would be beneficial to have two indexes, one starting with send, one with receive.

Tags:
© 2018 2uzhan.com Contact