title: Inverse of SQL LIKE '%value%'
body: <p>I have a MySQL table containing domain names:</p>
  
  <pre><code>+----+---------------+
  | id | domain        |
  +----+---------------+
  |  1 | amazon.com    |
  |  2 | google.com    |
  |  3 | microsoft.com |
  |    |     ...       |
  +----+---------------+
  </code></pre>
  
  <p>I'd like to be able to search through this table for a full hostname (i.e. 'www.google.com'). If it were the other way round where the table contained the full URL I'd use:</p>
  
  <pre><code>SELECT * FROM table WHERE domain LIKE '%google.com%'
  </code></pre>
  
  <p>But the inverse is not so straightforward. My current thinking is to search for the full hostname, then progressively strip off each part of the domain, and search again. (i.e. search for 'www.google.com' then 'google.com')</p>
  
  <p>This is not particular efficient or clever, there must be a better way. I am sure it is a common problem, and no doubt easy to solve!</p>