22 Votes

SQLite: IF(a, b, c) Syntax not working

Question by Anja Proggy | Last update on 2021-04-06 | Created on 2014-06-25

In MySQL, I am often using the syntax IF(a, b, c) for if-conditions. So, for example, something like this:

SELECT IF(a > 10, 0, 1);

Using this condition, I get returned 0 in case, a > 10 or 1 if not.

Up to now, I have worked only a few times with SQLite. But now, I would like to implement a similar IF condition in SQLite. Unfortunately, I only get an error message for this statement. Are there no if-statements possible in SQLite?

ReplyPositiveNegative
1Best Answer1 Vote

Of course, you can also use if conditions in SQLite. However, you have to use another syntax.

Your example above implemented in SQLite is:

CASE WHEN a > 10 THEN 0 ELSE 1 END

So, you have to realize it with CASE WHEN, THEN and ELSE and you should not forget the END at the end of the condition.
Last update on 2021-04-06 | Created on 2014-06-25

ReplyPositive Negative
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.