MySQL: searh by host name in field containing urls
        Posted  
        
            by Silver Light
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Silver Light
        
        
        
        Published on 2010-04-27T09:26:51Z
        Indexed on 
            2010/04/27
            9:33 UTC
        
        
        Read the original article
        Hit count: 165
        
Hello!
I have this database table:
id  | url
-----------------------------------------
1   | http://stackoverflow.com/
2   | http://www.google.com
3   | http://example.com/somepage
4   | https://another.net?id=88
5   | http://hello.org/index.php?hello=2
6   | http://google.com?q=hello+world
I need to search all fields, where URL belongs to a certain host.
For example, if I give the query 'google.com', it will return rows 2 and 6 (www is ignored). I get the host using PHP parse_url() function.
How this SQL query would look like?
© Stack Overflow or respective owner