I usq sqlite3 (on Android) and then try to return a default value, if your choose needs to handle NULL values.

Normally this works:

SELECT ifnull(NULL, 12);

Having a variable: Choose ifnull(var, 21) from (choose NULL as var) 21

However the moment I personally use a table which table is empty, i quickly do not get anything:

SELECT ifnull(_id, 1) FROM empty_table;
<nothing here>

Even coming back an easy number isn't feasible:

SELECT 234 FROM empty_table;
<nothing here>

How come which happen? How do i get something from it?

It's a little different.

When utilizing Choose with rows, ifnull() is examined once per row, which means you need a minumum of one row.

You can most likely try something:

SELECT IFNULL((SELECT _id FROM empty_table LIMIT 1), 1)

You cannot. A column from the table that contains no rows isn't equal to a null value

select 1 from the_table

SQL returns always one row (for the most part) for every input row. When the table is empty, you won't obtain a single row. When the table has 10000 rows, you're going to get 10000 time the most important (despite the fact that your program most likely only choose the first, it's somewhat inefficient).

SELECT ifnull(_id, 1) from the_table

That's also rather unspecified behavior: With no ORDER BY, you'll just obtain a random _id.

select 1

Within the situation when there's no table (not every databases support this), it is just like choosing from the table with only just one row (with no posts).

How do i get something from it?

What about

select ifnull(max(_id), 1) from the_table

Which will always return exactly one row, even if the table is empty, and also you know which _id you are receiving.

ifnull(_id, 1) inspections whether the need for _id is null or otherwise in every row from the query results.

When the table is empty, you will find no rows to check on, therefore the ifnull never will get examined.