Difference Between NullIf() and IfNull() in SQLite

SQLite has a function called nullif() and another function called ifnull(), each of which serve a different purpose.

  • nullif() allows you to treat certain values as NULL. You can think of it as “return NULL if …”.
  • ifnull() allows you to replace NULL values with another value. You can think of it as “if NULL, then …”.

So they basically do the opposite of each other. One replaces NULL values with another value, and the other replaces another value with NULL.

Continue reading

How Group_Concat() Works in SQLite

SQLite has a group_concat() function that allows you to concatenate multiple results returned for a column into one.

This is sometimes referred to as “string aggregation”.

For example, when querying a database, instead of having each column’s value output in a new row, you can use group_concat() to have them output as a comma separated list.

Continue reading