11 Vote

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

Question by Anja Proggy | 2014-06-25 at 09:56

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
Avatar
0Best Answer0 Votes

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.
2014-06-25 at 14:56

ReplyPositive Negative
Reply

Related Topics

SQLite: Reset AUTOINCREMENT

Question | 1 Answer

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.