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?
Related Topics
SQLite: String and Column Concatenation using SQLite
Info | 0 Comments
SQLite: Error "no such function: INSTR"
Question | 1 Answer
SQLite: Creating an Index on one or more Columns
Info | 0 Comments
SQLite: Check whether Table exists
Info | 0 Comments
SQLite: What is the ID of the last inserted row?
Info | 0 Comments
SQLite: Check or search for empty values
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.
Of course, you can also use if conditions in SQLite. However, you have to use another syntax.
Your example above implemented in SQLite is:
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