title: SELECT LAST_INSERT_ID()
body: <p>Can somebody explain how works MySQL function LAST_INSERT_ID(). I'm trying to get id of last inserted row in database, but every time get 1.</p>
  
  <p>I use mybatis.</p>
  
  <p>Example query is :</p>
  
  <pre><code>&lt;insert id="insertInto" parameterType="Something" timeout="0"&gt;
    INSERT INTO something (something) VALUES (#{something})
    &lt;selectKey resultType="int"&gt;
      SELECT LAST_INSERT_ID()
    &lt;/selectKey&gt;
  &lt;/insert&gt;
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>System.out.println("Id : " + id)
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Id : 1
  </code></pre>