c**t 发帖数: 2744 | 1 MS SQL:
where field = 'string'
or
where field like 'string'?
Both work, which one is right? |
c**t 发帖数: 2744 | 2 It seems "=" is faster. :-)
【在 c**t 的大作中提到】 : MS SQL: : where field = 'string' : or : where field like 'string'? : Both work, which one is right?
|
f*****g 发帖数: 15860 | 3 if u know the exact string you're looking ofr, why bother to use LIKE?
【在 c**t 的大作中提到】 : It seems "=" is faster. :-)
|
c**t 发帖数: 2744 | 4 One said LIKE is standard;
【在 f*****g 的大作中提到】 : if u know the exact string you're looking ofr, why bother to use LIKE?
|
n********a 发帖数: 68 | 5 It matters not which one performs better or which one is standard.
The only thing that matters is correctness.
If the question you query is trying to answer requires LIKE,
by all means, use LIKE, and forget about the performance.
Performance will only come to play when = or like will provide
the SAME CORRECT answer.
As fryking mentioned, if you know the exact string, use =.
LIKE will be the wrong answer.
It seems unlikely to me where = or like will be equivalent
and provide the same correct answ
【在 c**t 的大作中提到】 : One said LIKE is standard;
|
c**t 发帖数: 2744 | 6 1) select * from TBL
where email = 'w*****[email protected]'
2) select * from TBL
where like 'w*****[email protected]'
Time: 1) 00:00:01 2) 00:00:04
My observation is = faster for this case.
【在 n********a 的大作中提到】 : It matters not which one performs better or which one is standard. : The only thing that matters is correctness. : If the question you query is trying to answer requires LIKE, : by all means, use LIKE, and forget about the performance. : Performance will only come to play when = or like will provide : the SAME CORRECT answer. : As fryking mentioned, if you know the exact string, use =. : LIKE will be the wrong answer. : It seems unlikely to me where = or like will be equivalent : and provide the same correct answ
|
a*******t 发帖数: 891 | 7 =
use like for '%string%' search
【在 c**t 的大作中提到】 : MS SQL: : where field = 'string' : or : where field like 'string'? : Both work, which one is right?
|
s******s 发帖数: 508 | 8 To make your comparison meaningful, you need to give the table structure and
the index(es) on it.
I agree that generally = is more efficient than like since like uses range
scan while = is exact match.
【在 c**t 的大作中提到】 : 1) select * from TBL : where email = 'w*****[email protected]' : 2) select * from TBL : where like 'w*****[email protected]' : Time: 1) 00:00:01 2) 00:00:04 : My observation is = faster for this case.
|
c**t 发帖数: 2744 | 9 The TBL is a general one, no index(es) built on it. If the compiler is smart
enought, will it convert "email like 'whatever@..'" to "email = 'whatever@..'"?
For the time I gave which is meaningless without knowing the table strtucture
and index(es), you are damn right. :-) But I just tried to show the difference
【在 s******s 的大作中提到】 : To make your comparison meaningful, you need to give the table structure and : the index(es) on it. : I agree that generally = is more efficient than like since like uses range : scan while = is exact match.
|