Marek
Marek

Reputation: 149

Delete URLs with specific domains from MySQL database

I have URLs in column URL. I would like to delete all URLs from database with selected domains. In database are different domains. Do I need to use regex? For example, I have urls:

https://example.com/something/gnsgngdf
https://example.com/?%jgfingi
https://anotherdomain.net/?gdtfhj65
etc.

I would like to write one SQL expression to delete all URLs that begin with selected domain. Something like this:

DELETE FROM table WHERE url = regex: https://example.com

Upvotes: 2

Views: 589

Answers (3)

ScaisEdge
ScaisEdge

Reputation: 133360

In this case, you could use a simple like

 DELETE FROM table WHERE url  liKe 'https://example.com%'

Upvotes: 3

ave4496
ave4496

Reputation: 3018

DELETE FROM table WHERE url like 'https://example.com%'

No need for a regex. You can use the like operator. Now everything is deleted which starts with this URL.

See detailed explanation

Upvotes: 0

chazecka
chazecka

Reputation: 151

DELETE FROM tablename WHERE url like 'https://example.com%'

do not forget the %

Upvotes: 1

Related Questions