-2

Wanted to delete complete row, which contains NULL entries in sql with command

DELETE FROM student WHERE ID=NULL;

What is wrong in this code?

Filburt
  • 17,626
  • 12
  • 64
  • 115
Jks
  • 9
  • 2
  • 1
    1. Please state the specific error you are getting. 2. Please show the contents of the table - `SELECT * FROM student;` – andrzejwp Jan 03 '22 at 14:24
  • 1
    See [What's the difference between " = null" and " IS NULL"?](https://stackoverflow.com/q/2749044/205233) – Filburt Jan 03 '22 at 14:26
  • Take the time to look at what [NULL means](https://en.wikipedia.org/wiki/Null_(SQL)). You are effectively saying Delete where *Id is equivalent to an unknown quantity* - which it never is. – Stu Jan 03 '22 at 14:28

1 Answers1

3

Your syntax is incorrect you need to check for IS NULL

DELETE FROM student WHERE ID IS NULL;

Adding link to documentation thanks to D M

Working with NULL values

hawkstrider
  • 4,141
  • 16
  • 27
  • Relevant docs are [Working with NULL values](https://dev.mysql.com/doc/refman/8.0/en/working-with-null.html): "To test for `NULL`, use the `IS NULL` and `IS NOT NULL` operators" and "You cannot use arithmetic comparison operators such as `=`, `<`, or `<>` to test for `NULL`." – D M Jan 03 '22 at 14:26
  • Great!!! It worked. – Jks Jan 15 '22 at 05:53