Reputation: 1620
I have a table that looks roughly like this:
+----+-----+--------+-----------+--------+
+ ID + REG + SERIAL + IP + STATUS +
+----+-----+--------+-----------+--------+
+ 1 + 001 + d8dhwf + 192.168.x + 1 +
+----+-----+--------+-----------+--------+
And I'm trying to get the correct data from it in Python (v2.7) using the MySQLdb library. To be exact, I'm trying to just get 'REG' where 'STATUS' is 1 and 'REG' is not NULL (empty)
As such, I've attempted this:
cursor.execute("""SELECT reg FROM table WHERE status='1' AND reg IS NOT NULL""")
but the last "IS NOT NULL" seems to be compelty ignored although it does not give me a syntax error.
Anyone know how to maybe do it different? Or what I am missing?
Thanks!
Upvotes: 1
Views: 54
Reputation: 59212
If it is a VARCHAR
column, and you want to rule out rows where the value in the column is empty (which is not the same as NULL
), you should be using the condition
reg!=''
instead of
reg IS NOT NULL
Upvotes: 1