Print

Print


Ken Irwin asked:
> I wonder if it's possible to use LIKE with
> the results of a subquery, eg.:
> SELECT * FROM table WHERE ip [NOT LIKE ANYTHING IN] (SELECT
> ip_range FROM known_ips) where [NOT LIKE ANYTHING IN] is
> probably some different wording.

In general, you'd do this like (hah):

SELECT *
FROM table t
WHERE NOT EXISTS
(  SELECT *
   FROM known_ips
   WHERE ip = t.ip
)

> I have script that combs through our logs to weed out
> spiders, bots and whatnot, and it references a table full of
> known good IPs that are definitely real users. Right now I
> have this hideous long query that includes a "WHERE ip not
> like '136.227.%' and ip not like '123.345.%'
> and...". If there's a way to similarly slim down this
> statement, I would love to find it.

Unfortunately, SQL doesn't know anything about ip ranges.  But it looks
like your known_ips table contains individual ip addresses, not ranges,
so the above (or something similar) should work.

Andy Kohler / UCLA Library Info Technology
[log in to unmask] / +1 310 206 8312