
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Deleting Partial Data from a Field in MySQL
To delete partial data, use UPDATE command along with REPLACE(). Let us first create a table −
mysql> create table DemoTable1583 -> ( -> GameDetails text -> ); Query OK, 0 rows affected (1.38 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1583 values('<GameName>=Candy</GameName>,<GamePrice>2000</GamePrice>'); Query OK, 1 row affected (0.53 sec) mysql> insert into DemoTable1583 values('<GameName>=Lucky29</GameName>,<GamePrice>10000</GamePrice>'); Query OK, 1 row affected (0.25 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1583;
This will produce the following output −
+------------------------------------------------------------+ | GameDetails | +------------------------------------------------------------+ | <GameName>=Candy</GameName>,<GamePrice>2000</GamePrice> | | <GameName>=Lucky29</GameName>,<GamePrice>10000</GamePrice> | +------------------------------------------------------------+ 2 rows in set (0.00 sec)
Here is the query to delete partial data from a field in MySQL −
mysql> update DemoTable1583 set GameDetails=replace(GameDetails,'<GameName>=Candy</GameName>',''); Query OK, 1 row affected (0.38 sec) Rows matched: 2 Changed: 1 Warnings: 0
Let us check the table records once again −
mysql> select * from DemoTable1583;
This will produce the following output −
+------------------------------------------------------------+ | GameDetails | +------------------------------------------------------------+ | ,<GamePrice>2000</GamePrice> | | <GameName>=Lucky29</GameName>,<GamePrice>10000</GamePrice> | +------------------------------------------------------------+ 2 rows in set (0.00 sec)
Advertisements