Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filtering out NULL entries in a SQLite database

Tags:

null

sqlite

I'm using SQLite to retrieve data inside an iOS app I'm developing.

Of the dataset i've been given by the client there are a lot of entries than contain columns with NULL values.

I want to make sure I filter these out so they aren't shown in the app.

I've tried all sorts of different syntax combinations, with no joy, they still keep appearing.

This is my current SQL

select * from bn_main order by RANDOM() LIMIT 1

I need it to look in the 'meaning' column and perform a WHERE to identify and therefore remove any entries that have a NULL value in that column.

Anyone able to help?

like image 658
Simon Hume Avatar asked May 20 '26 10:05

Simon Hume


1 Answers

NULL is a special case.
That means you can't do something like WHERE meaning <> NULL.
Instead you would use IS / IS NOT, e.g.:

  select meaning 
    from bn_main 
   where meaning IS NOT NULL
order by RANDOM() LIMIT 1;

Edit based on comment:
If you've tried this and are still getting results, the values to which you refer are not NULLs.
Instead filter out columns containing whitespace:

  select meaning 
    from bn_main 
   where TRIM(meaning) <> ''
order by RANDOM() LIMIT 1;
like image 108
mechanical_meat Avatar answered May 23 '26 04:05

mechanical_meat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!