Monday 14 July 2014

Handling NULL's

I have a table with values below and want to delete the entire data except ID=2

SELECT * FROM ID;
DELETE FROM ID WHERE ID<>2 OR ID IS NULL;
(or)
DELETE FROM ID WHERE COALESCE(ID,0)<>2 ;

Most committed mistake:
DELETE FROM ID WHERE ID<>2 ;

No comments:

Post a Comment