Delete URLs with specific domains from MySQL database?


To delete URLs with specific domains, use DELETE and LIKE clause.

Let us first create a table −

mysql> create table DemoTable1361
    -> (
    -> URL text
    -> ) ;
Query OK, 0 rows affected (0.58 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable1361 values('Https://www.google.com//?id=1');
Query OK, 1 row affected (0.21 sec)
mysql> insert into DemoTable1361 values('Https://www.facebook.com//?id=2&name=John');
Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable1361 values('Https://www.yahoo.com//?id=3');
Query OK, 1 row affected (0.31 sec)
mysql> insert into DemoTable1361 values('Https://www.google.com//?id=1');
Query OK, 1 row affected (0.16 sec)

Display all records from the table using select statement −

mysql> select * from DemoTable1361;

This will produce the following output −

+-------------------------------------------+
| URL                                       |
+-------------------------------------------+
| Https://www.google.com//?id=1             |
| Https://www.facebook.com//?id=2&name=John |
| Https://www.yahoo.com//?id=3              |
| Https://www.google.com//?id=1             |
+-------------------------------------------+
4 rows in set (0.00 sec)

Here is the query to delete URLs with specific domains from MySQL database −

mysql> delete from DemoTable1361 where URL LIKE '%Https://www.google.com%';
Query OK, 2 rows affected (0.17 sec)

Let us check the table records once again −

mysql> select * from DemoTable1361;

This will produce the following output −

+-------------------------------------------+
| URL                                       |
+-------------------------------------------+
| Https://www.facebook.com//?id=2&name=John |
| Https://www.yahoo.com//?id=3              |
+-------------------------------------------+
2 rows in set (0.00 sec)
raja
Published on 08-Nov-2019 10:38:13
Advertisements