Search code examples
sqliteselectnullrowcell

Request rows with amount IS NULL (IS NOT NULL) cells in Sqlite3 (SELECT command)


Is it possible to create a request in Sqlite3 of the SELECT type, which will contain the condition "select a row where amount NULL (or IS NOT NULL) cells will be more (less) a certain number"?


Solution

  • With this query:

    SELECT * FROM tablename
    WHERE (col1 IS NULL) + (col2 IS NULL) + (col3 IS NULL) + .... > ?
    

    Each of the expressions (colX IS NULL) or (colX IS NOT NULL) evaluates to 1 for true or 0 for false, so you can compare their sum to the number ? that you want.