Click Upvote Click Upvote - 4 months ago 9
SQL Question

Difference between LIKE and = in MYSQL?

What's the difference between

SELECT foo FROM bar WHERE foobar='$foo'


AND

SELECT foo FROM bar WHERE foobar LIKE'$foo'

Answer

LIKE can do wildcard matching:

SELECT foo FROM bar WHERE foobar LIKE "Foo%"

If you don't need pattern matching, then use = instead of LIKE. It's faster and more secure. (You are using parameterized queries, right?)

Comments