Reputation: 101
I have two values in table PC and PC/name. But when I write a query,
select * from TransDetail TD where td.ModUserId like '%PC/%'
it gives me both results. Is there a way to get only one record?
Upvotes: 0
Views: 45523
Reputation: 5028
You should make your WHERE clause like this:
select *
from TransDetail TD
where TD.ModUserId ='PC'
This way you will get the results which are matched to 'PC' only.
The like that you made is giving your results of cases that PC can be start/middle/end of the field
Upvotes: 5
Reputation: 43
You should use this query instead for an exact match of the value PC:
SELECT * FROM TransDetail TD WHERE TD.ModUserId = 'PC';
When using % in the WHERE clause you are using a wildcard that stands for 0 or more occurrences of characters in that position.
Also, if you are actually using LIKE '%PC/%'
it should match the value PC/name and not the value PC, because of the extra '/' character in the statement.
Upvotes: 2
Reputation: 1904
Try this..
select * from TransDetail TD where td.ModUserId like '%PC'
Upvotes: 0