[SQL] The like operator and the asterisk

So I'm trying to perform a simple task - pull numbers from a table of representatives that have the area code 765.

The query functions properly when I write

WHERE X Like "(765*"

but not when I write

WHERE X Like "(765"

Why is this? What does that asterisk actually do that's making the difference? The only guess I can make is that it's acting as a wildcard and effectively saying "Find the (765 bit, I don't care what comes after it"...

Posted Sep 26, 2016, 6:31 AM UTC

21
elperroborrachotoo•

This is just how SQL is designed:

If the operator is LIKE, and the right hand side contains a question mark or an asterisk, do a pattern match instead of a string comparison.

It's not the asterisk doing that, but the code interpreting the statement.

[glob patterns](https://en.wikipedia.org/wiki/Glob_(programming\))


note: SQL by default uses _ and %, but many engines allow to alternately use ? and *

2