Mysql: Find rows where column value ends with a specific substring

前端 未结 4 1269
情书的邮戳
情书的邮戳 2021-02-18 19:20

I have a column url where all the values are urls. I\'m trying to update the value of a different column where-ever the aforementioned url ends with .pdf

4条回答
  •  忘掉有多难
    2021-02-18 19:51

    In your WHERE clause, use something like LOCATE('.pdf',url) > 0 to identify the record of interest.

    As pointed out, this will give you any url that contains '.pdf' in the string...

    If you definitely want the '.pdf' to be at the end, you can also try:

    LOWER(RIGHT(url,4)) = '.pdf'

    I would use LOWER or UPPER to deal with any case issues.

    You can also use LIKE %.pdf (again, watch out for upper/lower case issues) as suggested by others.

提交回复
热议问题