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')
精彩评论