I have a MySQL table containing domain names:
+----+---------------+ | id | domain | +----+---------------+ | 1 | amazon.com | | 2 | google.com | | 3 | microsoft.com | | | ... | +----+---------------+
I would like to be able to search in this table for the full host name (ie "www.google.com"). If it were the other way around, where the table contained the full URL that I would use:
SELECT * FROM table WHERE domain LIKE '%google.com%'
But the opposite is not so simple. My current thinking is to search for the fully qualified host name, then gradually remove each part of the domain and search again. (i.e. search for "www.google.com" and then "google.com")
This is not particularly effective or smart; there must be a better way. I am sure this is a common problem, and no doubt it is easy to solve!
source share