|
-
Jan 10th, 2007, 04:55 AM
#1
Thread Starter
Just Married
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
-
Jan 10th, 2007, 06:32 AM
#2
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.
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...
-
Jan 10th, 2007, 08:24 AM
#3
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.
-
Jan 10th, 2007, 08:26 AM
#4
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...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|