In this post, we will see how to resolve SQL: Select AS with IF condition
Question:I have a MSG table with columns
ITEM_ID, SELLER_ID, MSG_SENDER_ID and MSG_RECEIVER_IDto record the conversation between a buyer and seller for an item.
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!