LIKE ऑपरेटर के साथ DELETE का उपयोग
किसी टेबल से विशिष्ट स्ट्रिंग वाली सभी पंक्तियाँ हटाने के लिए LIKE के साथ DELETE उपयोग करें:
DELETE FROM table_name WHERE column_name LIKE '%string%' OR column_name LIKE 'string%' OR column_name LIKE '%string';
उदाहरण: "bar" टेबल बनाना और डेटा डालना
mysql> CREATE TABLE bar (
-> Id INT NOT NULL AUTO_INCREMENT,
-> Words LONGTEXT,
-> PRIMARY KEY(Id)
-> );
mysql> INSERT INTO bar(Words) VALUES('Javafoo');
mysql> INSERT INTO bar(Words) VALUES('fooMySQL');
mysql> INSERT INTO bar(Words) VALUES('Introductiontofoo C and C++');
mysql> INSERT INTO bar(Words) VALUES('Introduction to Node.js');
mysql> INSERT INTO bar(Words) VALUES('Introduction to Hibernate framework');
हटाने से पहले
mysql> SELECT * FROM bar;
+----+-------------------------------------+ | Id | Words | +----+-------------------------------------+ | 1 | Javafoo | | 2 | fooMySQL | | 3 | Introductiontofoo C and C++ | | 4 | Introduction to Node.js | | 5 | Introduction to Hibernate framework | +----+-------------------------------------+
"foo" वाली पंक्तियाँ हटाना
mysql> DELETE FROM bar
-> WHERE Words LIKE '%foo'
-> OR Words LIKE '%foo%'
-> OR Words LIKE 'foo%';
Query OK, 3 rows affected
हटाने के बाद
mysql> SELECT * FROM bar;
+----+-------------------------------------+ | Id | Words | +----+-------------------------------------+ | 4 | Introduction to Node.js | | 5 | Introduction to Hibernate framework | +----+-------------------------------------+
सरल विकल्प: WHERE Words LIKE '%foo%' अकेले भी काम करता है क्योंकि यह शुरुआत, मध्य और अंत सभी को कवर करता है।