mysql query when input contains more characters then db column
<p>I am trying to write a mysql query such that the search string that a user enters is the value in the database plus up to two additional characters (from a subset of 0-5 and a-b).</p>

<p>I had originally started doing the query using the mysql INSTR function, such that my query would be something like this:</p>

<pre><code>SELECT * FROM table WHERE INSTR(&lt;user_input&gt;, name) = 1;
</code></pre>

<p>But this obviously doesn't check what the additional characters are, or how many there are, so depending on the existing rows, it doesn't return the correct values. How can I write the query to do that?</p>

<p>For example, if I have the following rows in my DB:</p>

<pre><code>Name: ABCD
Name: LMNO
Name: A
</code></pre>

<p>If the user sends ABCD, or ABCD1, I want it to return the first row (using the INSTR method I was originally using, it would return both the first and last rows), but if they send A2B, it would return the last one.</p>