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
  • 40,185
  • 99
  • 257
  • 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,087
  • 3
  • 27
  • 41
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,303
  • 7
  • 48
  • 91
1
delete from tablename where meta_key = 'tel'
naveen goyal
  • 4,411
  • 2
  • 14
  • 26
1
DELETE FROM `table_name` WHERE meta_key = "tel";

For the future, try and read the docs.

marijnz0r
  • 914
  • 10
  • 21
1
DELETE FROM table
        WHERE meta_key= 'tel';

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

Rocketq
  • 4,776
  • 17
  • 70
  • 119