Results 1 to 4 of 4

Thread: Like

  1. #1

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Question Like

    Hi all
    Often we use = and LIKE in the SQL Query , But I want to know that what is the difference between = AND LIKE


    Code:
    SELECT * FROM Table WHERE Name ='shakti'
    Code:
    SELECT * FROM Table WHERE Name LIKE 'shakti'

    What is the difference?
    Thanks

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Like

    In your example - nothing

    However if you were to put
    SELECT * FROM Table WHERE Name LIKE 'shak*' or
    SELECT * FROM Table WHERE Name LIKE 'shak%' (depending on DAO/ADO respectively)
    Then the like does a pattern match check instead of exact match.


    Access however will match "ShAk" and "shak" (I think) on = .... you'd have to try some test data to confirm.

    Does that help.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Like

    The wildcard characters are different between databases as well.

    I believe Access requires the use of a * whereas SQL Server uses a % and does not recognize the * as valid. SQL Server won't give you an error, but you also don't get any results. As a test, I just did (from Query Analyser)
    Code:
    select * from tblappealro where prov_cd like '0%'
    And got 190 returns. When I did
    Code:
    select * from tblappealro where prov_cd like '0*'
    I got no error, but I also got no returns.

  4. #4
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Like

    LIKE will ignore indexes and do a table scan. That is a huge difference.

    = on a column that is an index will usually use that index - resulting in a speed increase for the query.

    LIKE, as already stated, is for wild-card searching - and if needed for that reason is an appropriate solution.

    btw - in MS SQL SERVER - case-sensitivity on searches in a server option - not sure how ACCESS handles it...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width