I understand that the "?" represent one character and the "*" is basically a wildcard, but could someone give some examples of practical applications of this function?
The wildcards are useful for when you can only identify a record set with a partial string.
For example:
If you have the following records in your db:
Customer ID Customer Name
----------- -------------
1 Smith
2 Smyth
3 Jones
4 Bobajob
You could fetch the first two records by using a clause in your selection criteria to return the first two records:
Customer Name like 'Sm*'
which would return the first two records. The question mark would also work in this case, as both names have only one character difference between them. i.e.
Customer Name like 'Sm?th'
would return the same thing.
The thing to bear in mind with the like function is that it's useful to return bunches of rows where only part of a field matches what you are looking for, but if you are querying a database, anything which has an asterisk or question mark in it will not use any indexes, so you may get some performance slow down.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.