0 votes
1 view
in SQL by (22.4k points)

It would seem that in general '=' is faster than 'like' when using wildcards. This appears to be the conventional wisdom. However, lets suppose I have a column containing a limited number of different fixed, hardcoded, varchar identifiers, and I want to select all rows matching one of them:

select * from table where value like 'abc%'

and

select * from table where value = 'abcdefghijklmn'

'Like' should only need to test the first three chars to find a match, whereas '=' must compare the entire string. In this case it would seem to me that 'like' would have an advantage, all other things being equal.

This is intended as a general, academic question, and so should not matter which DB, but it arose using SQL Server 2005.

1 Answer

0 votes
by (63.3k points)
edited by

Using '=' operator is faster than the LIKE operator in comparing strings because '=' operator compares the entire string but the LIKE keyword compares by each character of the string. We can use LIKE to check a particular pattern like column values starting with 'abc' in this case. You can use equal (=) operator if you are looking for a specific observation like 'abcdefghijklmn' in this case.

If you want to learn SQL then sign up for this SQL Certification course that provides instructor-led training, certification, and also job assistance

Related questions

0 votes
1 answer
asked Jul 13, 2019 in SQL by Tech4ever (22.4k points)
0 votes
1 answer
+2 votes
1 answer
asked Jun 26, 2019 in SQL by Vishal (107k points)
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...