I need to perform a SQL request to extract some data. I'm not sure if it's possible, and if so, I don't know how to do it. I believe an example is better to demonstrate what I'd like to do.
Lets assume a very simple table:
--------------------------
| ID | domain |
--------------------------
| 1 | example.com |
--------------------------
| 2 | stackoverflow.com |
--------------------------
I would like to retrieve the entry whose domain ends a specified string.
If user input were www.example.com, what request could I perform so the entry whose domain is example.com would be retrieved?
The string www.example.com is ended by the string example.com, that means I can't use % LIKE SQL construct, because I'm looking for a substring of the predicate.
Here is a potential dirty workaround to make it clearer:
user_input = "www.stackoverflow.com"
for domain in get_all_domains_from_db():
if user_input.endswith(domain):
print "It's this one!"
Ps: Let me know if something isn't clear.
static.srv1.example.comorbla.bli.meh.stackoverflow.com; therefore i can't trim safely for sure.