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
I might be oversimplifying... but based on your description, would LIKE solve your problem?
UPDATE YourTable
SET DifferentColumn = 'NewValue'
WHERE Url LIKE '%.pdf'
So it looks like you are looking for the like parameter.
for example:
SELECT column(s) FROM table WHERE URL LIKE '%.pdf'
Or you can update with
UPDATE table SET column = value, ..., WHERE URL LIKE '%.pdf'
The % is like saying anything before the .pdf is htis case.
Hope this helps.
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'
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.