0

I've data ike this

  1. PX01 , Dony, ASUS , Area1
  2. PX01 , Dony, ACER , Area1
  3. PX01 , Dony, SONY , Area1
  4. PX02 , ROKY, ASUS , Area2
  5. PX03 , Steve, ASUS , Area1

I want select data IF(Area2) Just Asus, but if(Area1) Asus and SONY. How to write if else in the where part of my query.

Sample

SELECT 
    .....  
WHERE if(Area = 'Area1') { PRODUCT = ASUS AND SONY} 
IF(Area = 'Area2' ) { PRODUCT = ASUS }  
IF(Area = 'Area3' ) { PRODUCT = SONY } 
1
  • Please include the exact output you are expecting here. Commented Nov 12, 2020 at 4:47

1 Answer 1

1
SELECT {columns list}
FROM {table name}
WHERE CASE Area WHEN 'Area1' THEN Product IN ('ASUS', 'SONY')
                WHEN 'Area2' THEN Product = 'ASUS'
                WHEN 'Area3' THEN Product = 'SONY'
                             ELSE NULL
                             END;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.