Inverse of SQL LIKE '%value%'

后端 未结 3 718
眼角桃花
眼角桃花 2021-02-04 19:48

I have a MySQL table containing domain names:

+----+---------------+
| id | domain        |
+----+---------------+
|  1 | amazon.com    |
|  2 | google.com    |
         


        
3条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-04 20:09

    You can use the column on the right of the like too:

    SELECT domain FROM table WHERE 'www.google.com' LIKE CONCAT('%', domain);
    

    or

    SELECT domain FROM table WHERE 'www.google.com' LIKE CONCAT('%', domain, '%');
    

    It's not particularly efficient but it works.

提交回复
热议问题