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

前端 未结 4 1260
情书的邮戳
情书的邮戳 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:44

    You can use a LIKE condition with a leading wildcard. %.pdf means the column must end in .pdf

    UPDATE mytable
    SET newcolumn = 'PDF found'
    WHERE yourcolumn LIKE '%.pdf'
    

    Alternatively you could use the right() function

    UPDATE mytable
    SET newcolumn = 'PDF found'
    WHERE right(yourcolumn,4) = '.pdf'
    

提交回复
热议问题