0

I am a front end developer in .net i have a question about the data comparison in SQ L whether it compares by value or by reference.

SELECT 1 WHERE NULL =NULL --> No Result

SELECT 1 WHERE 1=1 --> Return the result 1.

Thanks in Advance.

Yuck
  • 49,664
  • 13
  • 105
  • 135
bilal_izloo
  • 37
  • 1
  • 1
  • 9
  • http://stackoverflow.com/questions/3201192/what-does-delete-from-table-where-null-null-means – Praveen Prasannan Sep 22 '14 at 03:42
  • `WHERE NULL IS NULL` – Hogan Sep 22 '14 at 03:49
  • 2
    The best thing you can do as a developer coming from .NET to SQL is to *forget everything you know about null* as just about none of it applies. In SQL all things are compared *"by value"*. When it comes to null SQL interprets this semantically as any one of *missing information*, *unknown information*, or *information not provided*. The distinction is very subtle yet hugely important. Consider reading a primer on relational set theory before you do much more SQL work. – Yuck Sep 22 '14 at 03:49

1 Answers1

1

The comparison is done by value, but I think where you're getting confused is with NULL values which really mean "a missing value".

To compare against NULL, you'll want to use col_name IS NULL or col_name IS NOT NULL instead of the standard = or != operators.

For MySQL, refer to the Working with NULL Values documentation. T-SQL has less of a reference with IS [NOT] NULL

newfurniturey
  • 37,556
  • 9
  • 94
  • 102