-
Like
Hi all :wave:
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
-
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.
-
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.
-
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...