Im trying to delete all rows that have a value in the column ' toevoeging '
I made this query:
DELETE FROM gebruiksoppervlakte WHERE toevoeging = NOT NULL;
Why is this not possible? So I want to keep the rows that have NULL Thanks!
Im trying to delete all rows that have a value in the column ' toevoeging '
I made this query:
DELETE FROM gebruiksoppervlakte WHERE toevoeging = NOT NULL;
Why is this not possible? So I want to keep the rows that have NULL Thanks!
You need to use IS NOT NULL
instead of toevoeging = NOT NULL
:
DELETE
FROM gebruiksoppervlakte
WHERE toevoeging IS NOT NULL;
NULL
is something that lacks a value. So using IS NULL
or IS NOT NULL
means that your column is either lacking a value or not lacking a value.
Edit, this will delete everything in your table that has a value in the toevoeging
column. If you have empty strings that you want to delete, then you will want to use:
DELETE
FROM gebruiksoppervlakte
WHERE toevoeging = '';
See Demo.
If you want to delete the rows with null
values then you will use:
DELETE
FROM gebruiksoppervlakte
WHERE toevoeging IS NULL;
See Demo
Edit #2, based on our conversation in chat you are trying to delete all rows where there is a value but that value is not an empty string. Then the remaining rows need to be updated to null
in the column. As a result you need to use both a delete and an update:
DELETE
FROM gebruiksoppervlakte
WHERE toevoeging IS NOT NULL
and toevoeging <> '';
update gebruiksoppervlakte
set toevoeging = null;
See Demo
When using the WHERE clause to locate rows that have a NULL value, never use the “= NULL” comparison, instead always use the IS NULL or IS NOT NULL comparison operators.
So the correct query is :
DELETE FROM gebruiksoppervlakte WHERE toevoeging IS NOT NULL;
Because NULLs cannot be compared, the following works exactly the same as ... WHERE toevoeging IS NOT NULL
:
DELETE FROM gebruiksoppervlakte
WHERE toevoeging = toevoeging
;