Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>NULLs have special behavior: comparing anything with a NULL gives you back a <code>NULL</code>, which is something else than <code>false</code> or <code>0</code>. It means "unknown".</p> <p>For example, take this table:</p> <pre><code> user_id | gender ------------------ 1 | NULL 2 | 'M' 3 | 'F' 4 | 'F' </code></pre> <p><code>SELECT * FROM mytable WHERE gender = 'M'</code> will return 1 row, as expected</p> <p><code>SELECT * FROM mytable WHERE gender != 'M'</code> will return 2 rows, NOT 3 rows.</p> <p><code>SELECT * FROM mytable WHERE gender != 'M' OR gender IS NULL</code> will return the expected 3 rows.</p> <hr> <p>Edit: For some applications, using <code>0</code> (or, God forbid, another "magic number") instead of <code>NULL</code> is not even advisable (units or exact values are not relevant in this example): </p> <pre><code> Date | Temperature -------------------------- 2010-01-01 | 10 2010-01-02 | 4 2010-01-03 | 0 2010-01-04 | -22 2010-01-05 | -45 2010-01-06 | NULL 2010-01-07 | -34 </code></pre> <p>Here, the <code>NULL</code> on Jan 6th means "value unknown" - maybe because the temperature was so low that the thermometer probe stopped responding. However, it's a completely different meaning than Jan 3rd, when the temperature was <code>0</code>, that is, 0 degrees.</p> <p>Also, as @Bill Karwin mentions, NULLs behave specially in aggregate functions (<code>COUNT</code>,<code>SUM</code>,<code>AVG</code> etc.): calculating <code>AVG(Temperature)</code> on the above data would give you <code>-14.5</code>, as the NULL row is ignored.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload