How to do a case sensitive search in WHERE clause? The Next CEO of Stack OverflowCan't create...

Explicit solution of a Hamiltonian system

Should I tutor a student who I know has cheated on their homework?

How to make a variable always equal to the result of some calculations?

Was a professor correct to chastise me for writing "Prof. X" rather than "Professor X"?

How do I solve this limit?

'Given that' in a matrix

How to make a software documentation "officially" citable?

Why do remote companies require working in the US?

How can I get through very long and very dry, but also very useful technical documents when learning a new tool?

Customer Requests (Sometimes) Drive Me Bonkers!

Increase performance creating Mandelbrot set in python

Unreliable Magic - Is it worth it?

Describing a person. What needs to be mentioned?

How to be diplomatic in refusing to write code that breaches the privacy of our users

How can I open an app using Terminal?

How to use tikz in fbox?

Removing read access from a file

Is it a good idea to use COLUMN AS (left([Another_Column],(4)) instead of LEFT in the select?

What size rim is OK?

What is the difference between "behavior" and "behaviour"?

Return the Closest Prime Number

What is the purpose of the Evocation wizard's Potent Cantrip feature?

Any way to transfer all permissions from one role to another?

Why did we only see the N-1 starfighters in one film?



How to do a case sensitive search in WHERE clause?



The Next CEO of Stack OverflowCan't create Windows Login's on a case sensitive SQL Server 2005 Instance - MSG 15401Can PostgreSQL create a case sensitive database?MySQL case sensitive table names on LinuxHandling case-insensitive queries with case-sensitive dataHow to make MySQL table name case insensitive in Ubuntu?Returning case-sensitive input of case-insensitive array matchColumns names are case sensitive on postgresCase Sensitive Ordering within the CMS Server ListCan database objects be made case insensitive while keeping strings case sensitive?SQL Server on Linux: Case Sensitivity












19















I want case sensitive search in SQL query. But by default, MySQL does not consider the case of the strings.



Any idea on how to do a case sensitive search in SQL query?










share|improve this question



























    19















    I want case sensitive search in SQL query. But by default, MySQL does not consider the case of the strings.



    Any idea on how to do a case sensitive search in SQL query?










    share|improve this question

























      19












      19








      19


      4






      I want case sensitive search in SQL query. But by default, MySQL does not consider the case of the strings.



      Any idea on how to do a case sensitive search in SQL query?










      share|improve this question














      I want case sensitive search in SQL query. But by default, MySQL does not consider the case of the strings.



      Any idea on how to do a case sensitive search in SQL query?







      mysql select case-sensitive






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 19 '12 at 11:25









      Somnath MulukSomnath Muluk

      4893714




      4893714






















          4 Answers
          4






          active

          oldest

          votes


















          20















          by default, MySQL does not consider the case of the strings




          This is not quite true. Whenever you create database in MySQL, the database/schema has a character set and a collation. Each character set has a default collation; see here for more information.



          The default collation for character set latin1, which is latin1_swedish_ci, happens to be case-insensitive.



          You can choose a case-sensitive collation, for example latin1_general_cs (MySQL grammar):



          CREATE SCHEMA IF NOT EXISTS `myschema` 
          DEFAULT CHARACTER SET latin1
          COLLATE latin1_general_cs ;


          This has an effect on things like grouping and equality. For example,



          create table casetable (
          id int primary key,
          thing varchar(50)
          );

          select * from casetable;
          +----+-------+
          | id | thing |
          +----+-------+
          | 3 | abc |
          | 4 | ABC |
          | 5 | aBc |
          | 6 | abC |
          +----+-------+


          In a case-sensitive database, we get:



          select thing, count(*) from casetable group by thing;
          +-------+----------+
          | thing | count(*) |
          +-------+----------+
          | ABC | 1 |
          | aBc | 1 |
          | abC | 1 |
          | abc | 1 |
          +-------+----------+

          select * from casetable where thing = "abc";
          +----+-------+
          | id | thing |
          +----+-------+
          | 3 | abc |
          +----+-------+


          While in a case-insensitive database, we get:



          select thing, count(*) from casetable group by thing;
          +-------+----------+
          | thing | count(*) |
          +-------+----------+
          | abc | 4 |
          +-------+----------+

          select * from casetable where thing = "abc";
          +----+-------+
          | id | thing |
          +----+-------+
          | 3 | abc |
          | 4 | ABC |
          | 5 | aBc |
          | 6 | abC |
          +----+-------+


          Note that you can also change the collation from within a query. For example, in the case-sensitive database, I can do



          select * from casetable where thing collate latin1_swedish_ci = "abc";
          +----+-------+
          | id | thing |
          +----+-------+
          | 3 | abc |
          | 4 | ABC |
          | 5 | aBc |
          | 6 | abC |
          +----+-------+





          share|improve this answer































            12














            You always should state with your question which version of MySQL you're using, because MySQL is in steady development.



            Okay, back to your question:



            The string functions in MySQL are always case sensitive, so you could
            use any of the functions LOCATE, POSITION, or INSTR.



            For example:



            SELECT phone FROM user WHERE POSITION('term' IN user_name)>0;


            The pattern matching with regular expression (RLIKE or REGEXP) is
            always case sensitive for all versions of MySQL except the newest
            3.23.4.



            For example:



            SELECT phone FROM user WHERE user_name REGEXP 'term';


            For both the normal comparison (=) and the SQL pattern matching (LIKE)
            the behaviour depends on the fields that are involved:



            a. CHAR, VARCHAR,
            and all variants of TEXT fields do compare case insensitive.



            b. CHAR BINARY, VARCHAR BINARY
            and all variants of BLOB fields do compare case sensitive.



            If you compare a field from (a) with a field from (b), then the comparison will be case sensitive (case sensitivity wins). See chapter "7.2.7 String types" of the MySQL Reference Manual and look for the statements on sorting and comparisons.



            Starting with V3.23.0 it's also possible to force a comparison into case sensitivity with the cast operator BINARY, independent of the types of involved fields. See chapter "7.3.7 Cast operators" of the MySQL Reference Manual.



            So you also might change the type of user_name, or with V3.23.x try something like:



            SELECT phone FROM user WHERE BINARY username LIKE '%term%';





            share|improve this answer

































              1














              In my situation, I'm using Access 2010, but I had the same problem yet the solution is different: Use the StrComp() function and test its return to be zero.



              StrComp( thing, 'abc', 0) = 0



              Because StrComp() returns -1 if the first argument is "smaller", 1 if it is "larger", and 0 if it is "equal", when StrComp()=0, you have a case-sensitive match.



              See here, here or here.






              share|improve this answer

































                -2














                Try this for insensitive search, it works fine with great performance:



                "SELECT phone FROM user WHERE lower(user_name) like ".srtlower($username);





                share|improve this answer
























                  Your Answer








                  StackExchange.ready(function() {
                  var channelOptions = {
                  tags: "".split(" "),
                  id: "182"
                  };
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function() {
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled) {
                  StackExchange.using("snippets", function() {
                  createEditor();
                  });
                  }
                  else {
                  createEditor();
                  }
                  });

                  function createEditor() {
                  StackExchange.prepareEditor({
                  heartbeatType: 'answer',
                  autoActivateHeartbeat: false,
                  convertImagesToLinks: false,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: null,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader: {
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  },
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  });


                  }
                  });














                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function () {
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f15250%2fhow-to-do-a-case-sensitive-search-in-where-clause%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  4 Answers
                  4






                  active

                  oldest

                  votes








                  4 Answers
                  4






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  20















                  by default, MySQL does not consider the case of the strings




                  This is not quite true. Whenever you create database in MySQL, the database/schema has a character set and a collation. Each character set has a default collation; see here for more information.



                  The default collation for character set latin1, which is latin1_swedish_ci, happens to be case-insensitive.



                  You can choose a case-sensitive collation, for example latin1_general_cs (MySQL grammar):



                  CREATE SCHEMA IF NOT EXISTS `myschema` 
                  DEFAULT CHARACTER SET latin1
                  COLLATE latin1_general_cs ;


                  This has an effect on things like grouping and equality. For example,



                  create table casetable (
                  id int primary key,
                  thing varchar(50)
                  );

                  select * from casetable;
                  +----+-------+
                  | id | thing |
                  +----+-------+
                  | 3 | abc |
                  | 4 | ABC |
                  | 5 | aBc |
                  | 6 | abC |
                  +----+-------+


                  In a case-sensitive database, we get:



                  select thing, count(*) from casetable group by thing;
                  +-------+----------+
                  | thing | count(*) |
                  +-------+----------+
                  | ABC | 1 |
                  | aBc | 1 |
                  | abC | 1 |
                  | abc | 1 |
                  +-------+----------+

                  select * from casetable where thing = "abc";
                  +----+-------+
                  | id | thing |
                  +----+-------+
                  | 3 | abc |
                  +----+-------+


                  While in a case-insensitive database, we get:



                  select thing, count(*) from casetable group by thing;
                  +-------+----------+
                  | thing | count(*) |
                  +-------+----------+
                  | abc | 4 |
                  +-------+----------+

                  select * from casetable where thing = "abc";
                  +----+-------+
                  | id | thing |
                  +----+-------+
                  | 3 | abc |
                  | 4 | ABC |
                  | 5 | aBc |
                  | 6 | abC |
                  +----+-------+


                  Note that you can also change the collation from within a query. For example, in the case-sensitive database, I can do



                  select * from casetable where thing collate latin1_swedish_ci = "abc";
                  +----+-------+
                  | id | thing |
                  +----+-------+
                  | 3 | abc |
                  | 4 | ABC |
                  | 5 | aBc |
                  | 6 | abC |
                  +----+-------+





                  share|improve this answer




























                    20















                    by default, MySQL does not consider the case of the strings




                    This is not quite true. Whenever you create database in MySQL, the database/schema has a character set and a collation. Each character set has a default collation; see here for more information.



                    The default collation for character set latin1, which is latin1_swedish_ci, happens to be case-insensitive.



                    You can choose a case-sensitive collation, for example latin1_general_cs (MySQL grammar):



                    CREATE SCHEMA IF NOT EXISTS `myschema` 
                    DEFAULT CHARACTER SET latin1
                    COLLATE latin1_general_cs ;


                    This has an effect on things like grouping and equality. For example,



                    create table casetable (
                    id int primary key,
                    thing varchar(50)
                    );

                    select * from casetable;
                    +----+-------+
                    | id | thing |
                    +----+-------+
                    | 3 | abc |
                    | 4 | ABC |
                    | 5 | aBc |
                    | 6 | abC |
                    +----+-------+


                    In a case-sensitive database, we get:



                    select thing, count(*) from casetable group by thing;
                    +-------+----------+
                    | thing | count(*) |
                    +-------+----------+
                    | ABC | 1 |
                    | aBc | 1 |
                    | abC | 1 |
                    | abc | 1 |
                    +-------+----------+

                    select * from casetable where thing = "abc";
                    +----+-------+
                    | id | thing |
                    +----+-------+
                    | 3 | abc |
                    +----+-------+


                    While in a case-insensitive database, we get:



                    select thing, count(*) from casetable group by thing;
                    +-------+----------+
                    | thing | count(*) |
                    +-------+----------+
                    | abc | 4 |
                    +-------+----------+

                    select * from casetable where thing = "abc";
                    +----+-------+
                    | id | thing |
                    +----+-------+
                    | 3 | abc |
                    | 4 | ABC |
                    | 5 | aBc |
                    | 6 | abC |
                    +----+-------+


                    Note that you can also change the collation from within a query. For example, in the case-sensitive database, I can do



                    select * from casetable where thing collate latin1_swedish_ci = "abc";
                    +----+-------+
                    | id | thing |
                    +----+-------+
                    | 3 | abc |
                    | 4 | ABC |
                    | 5 | aBc |
                    | 6 | abC |
                    +----+-------+





                    share|improve this answer


























                      20












                      20








                      20








                      by default, MySQL does not consider the case of the strings




                      This is not quite true. Whenever you create database in MySQL, the database/schema has a character set and a collation. Each character set has a default collation; see here for more information.



                      The default collation for character set latin1, which is latin1_swedish_ci, happens to be case-insensitive.



                      You can choose a case-sensitive collation, for example latin1_general_cs (MySQL grammar):



                      CREATE SCHEMA IF NOT EXISTS `myschema` 
                      DEFAULT CHARACTER SET latin1
                      COLLATE latin1_general_cs ;


                      This has an effect on things like grouping and equality. For example,



                      create table casetable (
                      id int primary key,
                      thing varchar(50)
                      );

                      select * from casetable;
                      +----+-------+
                      | id | thing |
                      +----+-------+
                      | 3 | abc |
                      | 4 | ABC |
                      | 5 | aBc |
                      | 6 | abC |
                      +----+-------+


                      In a case-sensitive database, we get:



                      select thing, count(*) from casetable group by thing;
                      +-------+----------+
                      | thing | count(*) |
                      +-------+----------+
                      | ABC | 1 |
                      | aBc | 1 |
                      | abC | 1 |
                      | abc | 1 |
                      +-------+----------+

                      select * from casetable where thing = "abc";
                      +----+-------+
                      | id | thing |
                      +----+-------+
                      | 3 | abc |
                      +----+-------+


                      While in a case-insensitive database, we get:



                      select thing, count(*) from casetable group by thing;
                      +-------+----------+
                      | thing | count(*) |
                      +-------+----------+
                      | abc | 4 |
                      +-------+----------+

                      select * from casetable where thing = "abc";
                      +----+-------+
                      | id | thing |
                      +----+-------+
                      | 3 | abc |
                      | 4 | ABC |
                      | 5 | aBc |
                      | 6 | abC |
                      +----+-------+


                      Note that you can also change the collation from within a query. For example, in the case-sensitive database, I can do



                      select * from casetable where thing collate latin1_swedish_ci = "abc";
                      +----+-------+
                      | id | thing |
                      +----+-------+
                      | 3 | abc |
                      | 4 | ABC |
                      | 5 | aBc |
                      | 6 | abC |
                      +----+-------+





                      share|improve this answer














                      by default, MySQL does not consider the case of the strings




                      This is not quite true. Whenever you create database in MySQL, the database/schema has a character set and a collation. Each character set has a default collation; see here for more information.



                      The default collation for character set latin1, which is latin1_swedish_ci, happens to be case-insensitive.



                      You can choose a case-sensitive collation, for example latin1_general_cs (MySQL grammar):



                      CREATE SCHEMA IF NOT EXISTS `myschema` 
                      DEFAULT CHARACTER SET latin1
                      COLLATE latin1_general_cs ;


                      This has an effect on things like grouping and equality. For example,



                      create table casetable (
                      id int primary key,
                      thing varchar(50)
                      );

                      select * from casetable;
                      +----+-------+
                      | id | thing |
                      +----+-------+
                      | 3 | abc |
                      | 4 | ABC |
                      | 5 | aBc |
                      | 6 | abC |
                      +----+-------+


                      In a case-sensitive database, we get:



                      select thing, count(*) from casetable group by thing;
                      +-------+----------+
                      | thing | count(*) |
                      +-------+----------+
                      | ABC | 1 |
                      | aBc | 1 |
                      | abC | 1 |
                      | abc | 1 |
                      +-------+----------+

                      select * from casetable where thing = "abc";
                      +----+-------+
                      | id | thing |
                      +----+-------+
                      | 3 | abc |
                      +----+-------+


                      While in a case-insensitive database, we get:



                      select thing, count(*) from casetable group by thing;
                      +-------+----------+
                      | thing | count(*) |
                      +-------+----------+
                      | abc | 4 |
                      +-------+----------+

                      select * from casetable where thing = "abc";
                      +----+-------+
                      | id | thing |
                      +----+-------+
                      | 3 | abc |
                      | 4 | ABC |
                      | 5 | aBc |
                      | 6 | abC |
                      +----+-------+


                      Note that you can also change the collation from within a query. For example, in the case-sensitive database, I can do



                      select * from casetable where thing collate latin1_swedish_ci = "abc";
                      +----+-------+
                      | id | thing |
                      +----+-------+
                      | 3 | abc |
                      | 4 | ABC |
                      | 5 | aBc |
                      | 6 | abC |
                      +----+-------+






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Mar 19 '12 at 14:59









                      Matt FenwickMatt Fenwick

                      8931825




                      8931825

























                          12














                          You always should state with your question which version of MySQL you're using, because MySQL is in steady development.



                          Okay, back to your question:



                          The string functions in MySQL are always case sensitive, so you could
                          use any of the functions LOCATE, POSITION, or INSTR.



                          For example:



                          SELECT phone FROM user WHERE POSITION('term' IN user_name)>0;


                          The pattern matching with regular expression (RLIKE or REGEXP) is
                          always case sensitive for all versions of MySQL except the newest
                          3.23.4.



                          For example:



                          SELECT phone FROM user WHERE user_name REGEXP 'term';


                          For both the normal comparison (=) and the SQL pattern matching (LIKE)
                          the behaviour depends on the fields that are involved:



                          a. CHAR, VARCHAR,
                          and all variants of TEXT fields do compare case insensitive.



                          b. CHAR BINARY, VARCHAR BINARY
                          and all variants of BLOB fields do compare case sensitive.



                          If you compare a field from (a) with a field from (b), then the comparison will be case sensitive (case sensitivity wins). See chapter "7.2.7 String types" of the MySQL Reference Manual and look for the statements on sorting and comparisons.



                          Starting with V3.23.0 it's also possible to force a comparison into case sensitivity with the cast operator BINARY, independent of the types of involved fields. See chapter "7.3.7 Cast operators" of the MySQL Reference Manual.



                          So you also might change the type of user_name, or with V3.23.x try something like:



                          SELECT phone FROM user WHERE BINARY username LIKE '%term%';





                          share|improve this answer






























                            12














                            You always should state with your question which version of MySQL you're using, because MySQL is in steady development.



                            Okay, back to your question:



                            The string functions in MySQL are always case sensitive, so you could
                            use any of the functions LOCATE, POSITION, or INSTR.



                            For example:



                            SELECT phone FROM user WHERE POSITION('term' IN user_name)>0;


                            The pattern matching with regular expression (RLIKE or REGEXP) is
                            always case sensitive for all versions of MySQL except the newest
                            3.23.4.



                            For example:



                            SELECT phone FROM user WHERE user_name REGEXP 'term';


                            For both the normal comparison (=) and the SQL pattern matching (LIKE)
                            the behaviour depends on the fields that are involved:



                            a. CHAR, VARCHAR,
                            and all variants of TEXT fields do compare case insensitive.



                            b. CHAR BINARY, VARCHAR BINARY
                            and all variants of BLOB fields do compare case sensitive.



                            If you compare a field from (a) with a field from (b), then the comparison will be case sensitive (case sensitivity wins). See chapter "7.2.7 String types" of the MySQL Reference Manual and look for the statements on sorting and comparisons.



                            Starting with V3.23.0 it's also possible to force a comparison into case sensitivity with the cast operator BINARY, independent of the types of involved fields. See chapter "7.3.7 Cast operators" of the MySQL Reference Manual.



                            So you also might change the type of user_name, or with V3.23.x try something like:



                            SELECT phone FROM user WHERE BINARY username LIKE '%term%';





                            share|improve this answer




























                              12












                              12








                              12







                              You always should state with your question which version of MySQL you're using, because MySQL is in steady development.



                              Okay, back to your question:



                              The string functions in MySQL are always case sensitive, so you could
                              use any of the functions LOCATE, POSITION, or INSTR.



                              For example:



                              SELECT phone FROM user WHERE POSITION('term' IN user_name)>0;


                              The pattern matching with regular expression (RLIKE or REGEXP) is
                              always case sensitive for all versions of MySQL except the newest
                              3.23.4.



                              For example:



                              SELECT phone FROM user WHERE user_name REGEXP 'term';


                              For both the normal comparison (=) and the SQL pattern matching (LIKE)
                              the behaviour depends on the fields that are involved:



                              a. CHAR, VARCHAR,
                              and all variants of TEXT fields do compare case insensitive.



                              b. CHAR BINARY, VARCHAR BINARY
                              and all variants of BLOB fields do compare case sensitive.



                              If you compare a field from (a) with a field from (b), then the comparison will be case sensitive (case sensitivity wins). See chapter "7.2.7 String types" of the MySQL Reference Manual and look for the statements on sorting and comparisons.



                              Starting with V3.23.0 it's also possible to force a comparison into case sensitivity with the cast operator BINARY, independent of the types of involved fields. See chapter "7.3.7 Cast operators" of the MySQL Reference Manual.



                              So you also might change the type of user_name, or with V3.23.x try something like:



                              SELECT phone FROM user WHERE BINARY username LIKE '%term%';





                              share|improve this answer















                              You always should state with your question which version of MySQL you're using, because MySQL is in steady development.



                              Okay, back to your question:



                              The string functions in MySQL are always case sensitive, so you could
                              use any of the functions LOCATE, POSITION, or INSTR.



                              For example:



                              SELECT phone FROM user WHERE POSITION('term' IN user_name)>0;


                              The pattern matching with regular expression (RLIKE or REGEXP) is
                              always case sensitive for all versions of MySQL except the newest
                              3.23.4.



                              For example:



                              SELECT phone FROM user WHERE user_name REGEXP 'term';


                              For both the normal comparison (=) and the SQL pattern matching (LIKE)
                              the behaviour depends on the fields that are involved:



                              a. CHAR, VARCHAR,
                              and all variants of TEXT fields do compare case insensitive.



                              b. CHAR BINARY, VARCHAR BINARY
                              and all variants of BLOB fields do compare case sensitive.



                              If you compare a field from (a) with a field from (b), then the comparison will be case sensitive (case sensitivity wins). See chapter "7.2.7 String types" of the MySQL Reference Manual and look for the statements on sorting and comparisons.



                              Starting with V3.23.0 it's also possible to force a comparison into case sensitivity with the cast operator BINARY, independent of the types of involved fields. See chapter "7.3.7 Cast operators" of the MySQL Reference Manual.



                              So you also might change the type of user_name, or with V3.23.x try something like:



                              SELECT phone FROM user WHERE BINARY username LIKE '%term%';






                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Mar 23 '12 at 15:55









                              RolandoMySQLDBA

                              143k24227383




                              143k24227383










                              answered Mar 19 '12 at 12:11









                              TurgutTurgut

                              26317




                              26317























                                  1














                                  In my situation, I'm using Access 2010, but I had the same problem yet the solution is different: Use the StrComp() function and test its return to be zero.



                                  StrComp( thing, 'abc', 0) = 0



                                  Because StrComp() returns -1 if the first argument is "smaller", 1 if it is "larger", and 0 if it is "equal", when StrComp()=0, you have a case-sensitive match.



                                  See here, here or here.






                                  share|improve this answer






























                                    1














                                    In my situation, I'm using Access 2010, but I had the same problem yet the solution is different: Use the StrComp() function and test its return to be zero.



                                    StrComp( thing, 'abc', 0) = 0



                                    Because StrComp() returns -1 if the first argument is "smaller", 1 if it is "larger", and 0 if it is "equal", when StrComp()=0, you have a case-sensitive match.



                                    See here, here or here.






                                    share|improve this answer




























                                      1












                                      1








                                      1







                                      In my situation, I'm using Access 2010, but I had the same problem yet the solution is different: Use the StrComp() function and test its return to be zero.



                                      StrComp( thing, 'abc', 0) = 0



                                      Because StrComp() returns -1 if the first argument is "smaller", 1 if it is "larger", and 0 if it is "equal", when StrComp()=0, you have a case-sensitive match.



                                      See here, here or here.






                                      share|improve this answer















                                      In my situation, I'm using Access 2010, but I had the same problem yet the solution is different: Use the StrComp() function and test its return to be zero.



                                      StrComp( thing, 'abc', 0) = 0



                                      Because StrComp() returns -1 if the first argument is "smaller", 1 if it is "larger", and 0 if it is "equal", when StrComp()=0, you have a case-sensitive match.



                                      See here, here or here.







                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited 4 mins ago

























                                      answered May 28 '15 at 22:48









                                      Martin FMartin F

                                      236212




                                      236212























                                          -2














                                          Try this for insensitive search, it works fine with great performance:



                                          "SELECT phone FROM user WHERE lower(user_name) like ".srtlower($username);





                                          share|improve this answer




























                                            -2














                                            Try this for insensitive search, it works fine with great performance:



                                            "SELECT phone FROM user WHERE lower(user_name) like ".srtlower($username);





                                            share|improve this answer


























                                              -2












                                              -2








                                              -2







                                              Try this for insensitive search, it works fine with great performance:



                                              "SELECT phone FROM user WHERE lower(user_name) like ".srtlower($username);





                                              share|improve this answer













                                              Try this for insensitive search, it works fine with great performance:



                                              "SELECT phone FROM user WHERE lower(user_name) like ".srtlower($username);






                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Jan 9 '16 at 15:32









                                              ganjiganji

                                              1011




                                              1011






























                                                  draft saved

                                                  draft discarded




















































                                                  Thanks for contributing an answer to Database Administrators Stack Exchange!


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid



                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                  To learn more, see our tips on writing great answers.




                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function () {
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f15250%2fhow-to-do-a-case-sensitive-search-in-where-clause%23new-answer', 'question_page');
                                                  }
                                                  );

                                                  Post as a guest















                                                  Required, but never shown





















































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown

































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown







                                                  Popular posts from this blog

                                                  Parapolítica Índice Antecedentes El escándalo Proceso judicial Consecuencias Véase...

                                                  How to remove border from elements in the last row?Targeting flex items on the last rowHow to vertically wrap...

                                                  Tecnologías entrañables Índice Antecedentes Desarrollo Tecnologías Entrañables en la...