no results in WHERE LIKE without capital

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • djpaul
    New Member
    • Oct 2006
    • 137

    no results in WHERE LIKE without capital

    Hello!
    I have this query but it only works if the first letter is a capital.

    This is the query:
    Code:
    SELECT id, companyname, city FROM crediteuren 
    WHERE ( companyname LIKE '%Someon%' ) OR (city LIKE '%Someon%' )
    ORDER BY companyname
    And this doesn't work....:
    Code:
    SELECT id, companyname, city FROM crediteuren 
    WHERE ( companyname LIKE '%someon%' ) OR (city LIKE '%someon%' )
    ORDER BY companyname
    I realy don't get it....
    Thanks in advance!

    Paul
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    The fields in question are not CHAR, VARCHAR or TEXT.
    Or it is the collation - using a character set which is case sensitive.
    I don't fully understand collation but I always makes sure table and fields are latin1

    Comment

    • mwasif
      Recognized Expert Contributor
      • Jul 2006
      • 802

      #3
      It looks like you are using case sensitive collation. Provide the output of the following query so that we can suggest you something

      [CODE=mysql]DESC crediteuren;[/CODE]

      Comment

      • nathj
        Recognized Expert Contributor
        • May 2007
        • 937

        #4
        If it is case sesitivity and you want to maintain that then you could use something like:
        Code:
            SELECT id, companyname, city FROM crediteuren 
            WHERE ( LOWER(companyname) LIKE '%someon%' ) OR (LOWER(city) LIKE '%someon%' )
            ORDER BY companyname
        There is also an UPPER() function that could be used.

        Hope that helps
        nathj

        Comment

        • djpaul
          New Member
          • Oct 2006
          • 137

          #5
          Well, it was the collation.
          1 column was set to latin and the other was set to (i think is was..) latin1_ch
          Changed to latin1 and it worked!

          Thanks!

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            @nathj

            You can also just specify which COLLATE to use, instead of manipulating the string like that.
            Code:
            SELECT ...
            WHERE col1 LIKE '%something%' COLLATE latin1_general_ci
            OR    col2 LIKE '%something%' COLLATE latin1_general_cs;
            There the first column would be search using the case-insensitive latin1 collation, but the second one using the case-sensitive version.

            Comment

            Working...