I'm trying to do a MySQL query in phpMyAdmin. I want to find an entry where fieldone is not NULL or is not empty/blank as I inherited the system so fields are set to NULL and some are just blank.
Anyways, Here is the query I'm trying
SELECT fieldone, fieldtwo
FROM tableone
WHERE fieldone != ' '
OR fieldone IS NOT NULL
And
SELECT fieldone, fieldtwo
FROM tableone
WHERE fieldone <> ' '
OR fieldone IS NOT NULL
Both show an error #1064 on the line that contains
WHERE fieldone != ' '
And
WHERE fieldone <> ' '
The NOT NULL part works great, its just trying to find any fields that are blank.
SELECT fieldone, fieldtwo
FROM tableone
WHERE fieldone != ''
OR fieldone IS NOT NULL
SELECT fieldone, fieldtwo
FROM tableone
WHERE fieldone <> ''
OR fieldone IS NOT NULL
When you mean NULL value then don't include a space between your '' so it means NO CONTENT
You could try this:
SELECT fieldone, fieldtwo
FROM tableone
WHERE fieldone IS NOT NULL
AND TRIM(fieldone) <> ''
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With