0

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
younus
  • 101
  • 2
  • 2
  • 10
  • 1
    Keep in mind the `%` signifies a wildcard when using `LIKE`. So '%PC%' will match anything with PC in it. '%PC' will match ending in PC, and 'PC%' will match beginning with PC. 'PC' will match exactly PC. – Devon Bessemer Jan 29 '15 at 17:44

3 Answers3

5

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

The Dr.
  • 556
  • 1
  • 11
  • 24
roeygol
  • 4,908
  • 9
  • 51
  • 88
2

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.

LyzandeR
  • 37,047
  • 12
  • 77
  • 87
Ana C.
  • 43
  • 5
0

Try this..

select * from TransDetail TD where td.ModUserId like '%PC'

SoulTrain
  • 1,904
  • 1
  • 12
  • 11