Page 1 of 1

Selecting the items that don't match - SQLite

Posted: Tue Sep 15, 2015 2:47 am
by quailcreek
Seems like this should work but alas... no-joy. I'm trying to select all of theNames where theType does not match the string. It seems that SQLite doesn't like the <> because it ignores it. What is the syntax to accomplish this?

Code: Select all

  put "SELECT theName FROM MyNames WHERE theType <> 'Production' OR theType <> 'Device'" into tSQLStatement

Re: Selecting the items that don't match - SQLite

Posted: Tue Sep 15, 2015 3:59 am
by Simon
Hi quailcreek,
Did you try "!="

Simon

Re: Selecting the items that don't match - SQLite

Posted: Tue Sep 15, 2015 5:21 am
by quailcreek
Yep, I tried that Simon. It gets ignored too. Seems like it should throw an error but it doesn't

Re: Selecting the items that don't match - SQLite

Posted: Tue Sep 15, 2015 7:18 am
by SparkOut
Are you sure the <> is being ignored?
It looks like your query will return all results because all of the records will be either not equal to production or not equal to device. (Everything)
Try changing OR to AND in the query.

Re: Selecting the items that don't match - SQLite

Posted: Tue Sep 15, 2015 6:23 pm
by quailcreek
Hi Sparkout,
That did it. Changed OR to AND and now both <> and != work. Seems somehow counter intuitive. I would have thought that OR meant the string could contain either Production or Device and AND meant the string needs to contain both. I guess the way SQLite does the boolean is exclude (Production AND Device). Hmm... looks like I explained it to myself.

Thanks, Sparkout.

Re: Selecting the items that don't match - SQLite

Posted: Tue Sep 15, 2015 9:44 pm
by SparkOut
This is actually normal boolean resolution. It might look counterintuitive at first glance but really it is quite logical.
What you were asking the query to match is where the first condition was true (theType <> 'Production') OR the second condition was true (theType <> 'Device') . If theType is Production then the first condition is false so the second condition will be checked. If theType is Production then it obviously is not Device so the overall query will resolve true and return the record, and vice versa for theType being Device. Thus every record would be returned.

Re: Selecting the items that don't match - SQLite

Posted: Tue Sep 15, 2015 9:57 pm
by quailcreek
Thanks, Sparkout. It works a little differently then I thought but it makes sense.