开发者

What is the proper way to insert an if statement into a mysql query

What is the property way to insert an IF statement into a mysql query?

SELECT * FROM table WHERE (column1 > 'value')

What if I wanted to put a condition within that query like:

SELECT * FROM table WHERE ((column1 开发者_Go百科> 'value')and(IF column2 = 'n' THEN WHERE column3 > '5'))


Combine your conditions with AND and OR:

 SELECT * FROM table WHERE
     column1 > 'value' AND (column2 <> 'n' OR column3 > '5')


how about a case statement?


This should do what you want

SELECT * FROM table 
WHERE (column1 > 'value' and column2 != 'n')
    OR (column1 > 'value' and column2 = 'n' and column3 > '5')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜