I've few emp names like
- john,1
- devil's
- corn
something like this
Now when i'm searching for these names I'm using
select * from emp where empname like ('john,1,devil's,corn')
But I'm not getting expected values also I'm getting error because emp name contains special charecters like , and '.
Can someone help me out how to solve this?
use keyword escape to mention escape character for the query.
This assumes you have 3 discrete names in your example string
Exact match. you need to double up quotes.
You can't LIKE/IN in SQL Server too.
if you use mysql:
For most versions of SQL, you need to escape the single quote, for example.
Also, the above example is looking for a very specific string value, you need to include * or ? as wildcard characters, so to look for all empname's like devil's, use
Another example
If you are looking for an empname of "devil's" then I agree with the use of the escape character that Sachin and Ratinho used.
However, the
like
clause is used for something that is like another. For example, if you are looking for something that starts with "devil's" then you might usewhich would match
but not
If you want to match an empname with "devil's" in the middle, then you might use