How do the SQL “IS” and “=” operators differ?

后端 未结 5 2071
粉色の甜心
粉色の甜心 2021-01-03 21:59

I am building some prepared statements that use parametrized values. As an example:

SELECT * FROM \"Foo\" WHERE \"Bar\"=@param

Sometimes

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-03 22:13

    What specific database are you using?

    If you're doing searches based on null (or not null), using IS is the way to go. I cannot provide a technical reason but I use this syntax all the time.

    SELECT * FROM Table WHERE Field IS NULL
    
    SELECT * FROM Table WHERE Field IS NOT NULL
    

提交回复
热议问题