title: MySQL SELECT row based on prefix
body: <p>Im attempting to do a SELECT on data in a table that contains prefixes, and I have the "keyword".</p>
  
  <p>So unlike a normal search where the prefix/keyword is contained in the row data, and that the prefix/keyword is shorter (or contained in) a possible row of data. </p>
  
  <p>This is the opposite. If have prefixes in rows and I want to find the best matching row based on the (longer) word/phase. </p>
  
  <pre><code>CREATE TABLE table1 (id INT NOT NULL AUTO_INCREMENT, keyCode VARCHAR(45) NULL, Username VARCHAR(45) NULL, PRIMARY KEY (id));
  
  INSERT INTO table1(keyCode,Username)VALUES('123','Peter')
  INSERT INTO table1(keyCode,Username)VALUES('456','Paul')
  INSERT INTO table1(keyCode,Username)VALUES('1234','John')
  
  </code></pre>
  
  <p>Now let's say the phrase I have been given is longer than the prefix in the data.</p>
  
  <p>Like this:</p>
  
  <pre><code>SELECT * FROM table1 WHERE keyCode LIKE '123456%';
  </code></pre>
  
  <p>I know this will not work, but I would like to return the Row with User 'John'.</p>
  
  <p>How? 
  (I can use stored procedures)</p>