In this post, we will see how to resolve SQL: Select AS with IF condition
Question:
I have a MSG table with columnsITEM_ID, SELLER_ID, MSG_SENDER_ID and MSG_RECEIVER_ID
to record the conversation between a buyer and seller for an item.ITEM_ID | SELLER_ID | MSG_SENDER_ID | MSG_RECEIVER_ID |
---|---|---|---|
5 | 1 | 1 | 2 |
5 | 1 | 2 | 1 |
I need to select SELLER and BUYER. In this case seller = 1 and buyer = 2. The logic is: if SELLER_ID == MSG_SENDER_ID then buyer = MSG_RECEIVER_ID. then if SELLER_ID == MSG_RECEIVER_ID then buyer = MSG_SENDER_ID.
What should the query be like?
Best Answer:
Are you looking for this?If you have better answer, please add a comment about this, thank you!
Source: Stackoverflow.com