- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to delete fields with values more than a particular value in MySQL?
Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, PlayerName varchar(100), PlayerScore int ); Query OK, 0 rows affected (0.97 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(PlayerName,PlayerScore) values('Chris',780); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable(PlayerName,PlayerScore) values('Sam',1100); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable(PlayerName,PlayerScore) values('Mike',900); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(PlayerName,PlayerScore) values('Bob',890); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(PlayerName,PlayerScore) values('Carol',1000); Query OK, 1 row affected (0.20 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----+------------+-------------+ | Id | PlayerName | PlayerScore | +----+------------+-------------+ | 1 | Chris | 780 | | 2 | Sam | 1100 | | 3 | Mike | 900 | | 4 | Bob | 890 | | 5 | Carol | 1000 | +----+------------+-------------+ 5 rows in set (0.00 sec)
Following is the query to delete fields with values more than a particular value in MySQL −
mysql> delete from DemoTable where PlayerScore > 900; Query OK, 2 rows affected (0.18 sec)
Let us check the table records once again.
mysql> select *from DemoTable;
This will produce the following output −
+----+------------+-------------+ | Id | PlayerName | PlayerScore | +----+------------+-------------+ | 1 | Chris | 780 | | 3 | Mike | 900 | | 4 | Bob | 890 | +----+------------+-------------+ 3 rows in set (0.00 sec)
Advertisements