Web Analytics Made Easy -
StatCounter Numbers + Letters Match in WHERE clause - CodingForum


No announcement yet.

Numbers + Letters Match in WHERE clause

  • Filter
  • Time
  • Show
Clear All
new posts

  • Numbers + Letters Match in WHERE clause


    Right now I have this as my mysql query:

    SELECT * FROM rofl WHERE id='13159' LIMIT 1
    This returns the correct table. My question is though if I add a letter to it like this:

    SELECT * FROM rofl WHERE id='13159f' LIMIT 1
    Why does it still return the row with the column id 13159? Its like it is ignoring the "f" and still returning the row as if it wasn't there.

    If I take out all the numbers and just have it as "f" it says there is no row.

    If I take out the "f" and replace it with a "5" or something, it also says there is no row.

    Any ideas on why numbers + letters are acting this way in the WHERE clause, and how I should fix it?

    Thanks in advance for any help!

  • #2
    If your id column is numeric, the value on the right side of the = is parsed as a number, up to the first non-numeric digit. The "f" or any other non-numeric character you put there is a stop character.

    If you are only expecting a number, you either need to validate that it only contains numeric digits or you need to cast it as an integer.
    Last edited by CFMaBiSmAd; Apr 4, 2009, 03:33 PM. Reason: fixed case -> cast
    Finding out HOW to do something is called research, i.e. keep searching until you find the answer. After you attempt to do something and cannot solve a problem with it yourself, would be when you ask others for help.


    • #3
      Ok, thanks

      I'll just have to validate it.