PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, January 15, 2022

[FIXED] SQL statement to remove part of an URL on column

 January 15, 2022     mariadb, mysql, phpmyadmin, replace, sql     No comments   

Issue

I have a videos table with a column URL with many different URL types

https://google.com/questions/ask?963
https://google.com/embed/ask
https://google.com/top/123.html
https://video.net/embed-ask?963
https://video.net/embed-123.html
https://video.net/top?123.html

I need to delete part of a specific URL (delete embed-) from

https://video.net/embed-75mdabvgl3do.html

to

https://video.net/75mdabvgl3do.html

I have tray this SQL but return an empty result (0 rows affected)

UPDATE `videos` SET url = REPLACE(url, '%video.net/embed-%', '%video.net/%') WHERE `url` LIKE '%video.net/embed-%';

Solution

You could try this:

UPDATE videos
SET url = REPLACE(url, 'video.net/embed-', 'video.net/')
WHERE url LIKE '%video.net/embed-%';

This hopefully would be specific enough of a replacement. If not, we could consider using regular expressions (available if using MySQL 8+).



Answered By - Tim Biegeleisen
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing