title: Why are strings matched to a primary key when it is set to zero (MySQL)?
body: <p>I have encountered a strange behaviour in MySQL that I cannot understand. I have a table where I have a row where the primary key is 0 (zero). The strange thing is that any string seems to match that row.</p>
  <p>The SQL commands below creates a simple table with columns <code>id</code> and <code>text</code>. Then I add a simple row to the table, and modifies the <code>id</code> to be zero.</p>
  <pre><code>DROP TABLE IF EXISTS test;
  CREATE TABLE test (
      id INT NOT NULL AUTO_INCREMENT,
      text VARCHAR(45) NOT NULL,
  PRIMARY KEY (id));
  INSERT INTO test (text) VALUES (&quot;Hello World!&quot;);
  UPDATE test SET id = 0 WHERE (id = 1);
  </code></pre>
  <p>After these commands the table looks like this:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>id</th>
  <th>text</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>0</td>
  <td>Hello world!</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Now if I run the following command I expect an empty result, but the row with id=0 is returned. This won't happen if id = 1:</p>
  <pre><code>SELECT * FROM test WHERE id = &quot;test&quot;;
  </code></pre>
  <p>Returns the following unexpected result:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>id</th>
  <th>text</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>0</td>
  <td>Hello world!</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Is this a bug, or is there some kind of explaination that I get a row with <code>id=0</code>? If I change it back to <code>id=1</code>, then an empty result is return as expected</p>