Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between "LIKE" and "=" in SQL?

Is there any difference between:

SELECT * FROM users WHERE username="davyjones" 

and

SELECT * FROM users WHERE username LIKE "davyjones" 
like image 496
aviraldg Avatar asked Oct 01 '09 16:10

aviraldg


People also ask

Which is faster like or in SQL?

1 Answer. 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.

Can you use like and in in SQL?

There is no combination of LIKE & IN in SQL, much less in TSQL (SQL Server) or PLSQL (Oracle). Part of the reason for that is because Full Text Search (FTS) is the recommended alternative.

What is the difference between operator and like operator?

Example. Other than the difference of having wildcard characters, %, and _, there is a significant difference between LIKE and = operators is that LIKE operator does not ignore the trailing spaces while = operator ignores the trailing spaces.

What is the difference between like and Ilike?

The keyword ILIKE can be used instead of LIKE to make the match case insensitive according to the active locale. This is not in the SQL standard but is a PostgreSQL extension. The operator ~~ is equivalent to LIKE , and ~~* corresponds to ILIKE .


1 Answers

LIKE allows partial matching / use of wildcards, while = checks for exact matches.

For example

SELECT * FROM test WHERE field LIKE '%oom'; 

Will return rows where field value is any of the following:

Zoom, Boom, Loom, Groom 
like image 173
code_burgar Avatar answered Sep 25 '22 00:09

code_burgar