3

I have a table with a column meta_key … I want to delete all rows in my table where meta_key matches some string.

enter image description here

For instance I want to delete all 3 rows with "tel" in it - nut just the cell but the entire row. How can I do that with a mysql statement?

matt
  • 42,713
  • 103
  • 264
  • 397
  • delete from table where meta_key = 'tel' – jarlh May 27 '15 at 09:32
  • possible duplicate of [how to delete certain row from mysql table?](http://stackoverflow.com/questions/18378190/how-to-delete-certain-row-from-mysql-table) – Rocketq May 27 '15 at 09:41

5 Answers5

5

The below query deletes the row with strings contains "tel" in it :

   DELETE FROM my_table WHERE meta_key like '%tel%';

This is part of Pattern matching.

If you want the meta_key string to be equal to "tel" then you can try below:

   DELETE FROM my_table WHERE meta_key = 'tel'

This is a simple Delete

Viraj Nalawade
  • 3,137
  • 3
  • 28
  • 44
1
DELETE FROM table WHERE meta_key = 'tel' //will delete exact match

DELETE FROM table WHERE meta_key = '%tel%'//will delete string contain tel
Sachu
  • 7,555
  • 7
  • 55
  • 94
1
delete from tablename where meta_key = 'tel'
naveen goyal
  • 4,571
  • 2
  • 16
  • 26
1
DELETE FROM `table_name` WHERE meta_key = "tel";

For the future, try and read the docs.

marijnz0r
  • 934
  • 10
  • 23
1
DELETE FROM table
        WHERE meta_key= 'tel';

In addition you can use limit to specify the amount of rows to delete

Rocketq
  • 5,423
  • 23
  • 75
  • 126