Return to Snippet

Revision: 3707
at September 4, 2007 07:28 by pablazo

Initial Code
Sometimes you need to think backwards.

Here was the problem. I needed to match up some IP address ranges to the company that owns them. Looking for a simple solution to the problem I came up with storing the IP address block patterns in the database as follows:


Any idea why I choose % as the wildcard?

That's right - it's the wildcard operator in SQL for the LIKE statement.

So now when I have have an IP address, I can do what I like to call a backwards LIKE query:

SELECT company, ip_pattern
FROM company_blocks
WHERE '' LIKE ip_pattern

This works on SQL Server and MySQL, and I would think it should work fine on any database server.

Initial URL

Initial Description

Initial Title
Backwards LIKE Statements

Initial Tags

Initial Language