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
.
Can anyone help me with this? I haven't found an answer here on SO.
In Standard SQL, we use the ends_with() function to determine if a substring is a suffix of another. The function will take the value1 and value2 as string or a sequence of bytes. It will then evaluate if value2 is a suffix of value1.
MySQL query string contains using LOCATE We will be using the LOCATE() function for the solution. LOCATE(substr, str) function returns the first occurrence of the substring passed in as parameters. Here substr is the substring passed in as the first argument, and str is the string passed in as the second argument.
METHOD 1 : Using LIMIT clause in descending orderof specified rows from specifies row. We will retrieve last 5 rows in descending order using LIMIT and ORDER BY clauses and finally make the resultant rows ascending. Since Employee table has IDs, we will perform ORDER BY ID in our query.
I might be oversimplifying... but based on your description, would LIKE
solve your problem?
UPDATE YourTable SET DifferentColumn = 'NewValue' WHERE Url LIKE '%.pdf'
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With