名宏 鄭
名宏 鄭

Reputation: 115

mysql if elseif syntax condition

If I have two parameter "parameterX" and "parameterY"

and I'll using "parameterX" and "parameterY" to commend sql snytax

like as

select * from test.test where 
IF(parameterY!=0)
 THEN test.test.'x'=parameterX AND test.test.'y'=parameterY 
ELSE IF
 test.test.'x'=parameterX 
END IF

I know this's can't work But I want to know have a other way like it and it can work in mysql

Upvotes: 1

Views: 183

Answers (2)

Oliv
Oliv

Reputation: 10812

Or easier (than @diehud's answer):

select * from test.test where 
test.test.'x'=parameterX AND (test.test.'y'=parameterY OR parameterY=0)

Upvotes: 1

dieuhd
dieuhd

Reputation: 1326

I think dont need use IF ELSE syntax

select * from test.test where 
(parameterY!=0 and test.test.'x'=parameterX AND test.test.'y'=parameterY)
OR (parameterY = 0 and test.test.'x'=parameterX )

Upvotes: 1

Related Questions