Reputation: 1958
I have following fields in my ad_table table:
+----------------------------------------------------------+
|ADVT_ID | RELATIVE_ID | AD_TYPE | AD_LOCATION | AD_IMAGE |
+----------------------------------------------------------+
|1 | 2 | FP | H | test1.jpg |
|2 | 0 | FP | H | test2.jpg |
|3 | 0 | TB | H | test3.jpg |
+----------------------------------------------------------+
I want to use two if statements in mysql query. I want to retrieve data from table using mysql query in this format:
FIRST IF STATEMENT :
if (AD_TYPE = 'FP' && AD_LOCATION = 'H')
then select all data from
table where RELATIVE_ID !=0
SECOND IF STATEMENT :
if(AD_TYPE != 'FP' && AD_LOCATION != 'H')
then select all data from
table where RELATIVE_ID =0
So how to do that in mysql query?
Upvotes: 4
Views: 105
Reputation: 13218
You can try:
SELECT *
FROM ad_table
WHERE (AD_TYPE = 'FP' AND AD_LOCATION = 'H' AND RELATIVE_ID !=0)
OR (AD_TYPE != 'FP' AND AD_LOCATION != 'H' AND RELATIVE_ID =0)
Upvotes: 4