ACC: Like vs. = with Wildcard Characters in Query Searches

Last reviewed: May 28, 1997
Article ID: Q88166
The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1, 2.0, 7.0, 97

SUMMARY

Novice: Requires knowledge of the user interface on single-user computers.

When you are searching a string by using wildcards (for example, * or ?), you must use Like or Not Like in the Criteria field, rather than using = or <>. When you use the = or <> operators, Microsoft Access treats them as actual characters to search for.

MORE INFORMATION

If you have a table with one column called Col_Name and the following four records

   Foos
   Foosball
   Foos ball
   Foos*

and you create a query based on the table with the criteria

   ="Foos*"

your query will return:

   Foos*

But, if your criteria is

   Like "Foos*"

your query will return the following four records:

    Foos
    Foosball
    Foos ball
    Foos*

The SQL statements built by Microsoft Access for these queries are as follows.

The SQL statement using Like is:

   SELECT  DISTINCTROW tablename.Col_Name
   FROM [tablename]
   WHERE ((tablename.Col_Name Like "foos*"));

The SQL statement using = is:

   SELECT  DISTINCTROW tablename.Col_Name
   FROM [tablename]
   WHERE ((tablename.Col_Name="foos*"));
 

	
	


Keywords : kbusage QryOthr
Version : 1.0 1.1 2.0 7.0 97
Platform : WINDOWS
Hardware : x86
Issue type : kbinfo


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: May 28, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.