-5

I have JSON data continuously inserted into a DB table but there are some rows which I need to delete concurrently based on the column value. For eg., I need to delete the rows which have a column value (time_min) of more than 90 minutes.

ID    time_min
1       50
2       30
3       91
4       40
5       93
6       95
7       40

Here I need to delete rows containing values more than 90 in time_min column.

This is the current code I'm using.

if($time_min >= 91){
        $sql = "truncate table_name";
        if ($conn->query($sql) === TRUE) {
            echo "Rows Dropped";
        }
    }

It clearly is deleting the entire table values which mess up in the loading of new values. I would just want the rows that have column value of more than 90 in time_min (column name) to be deleted.

Would appreciate if someone can guide me on this.

MLavoie
  • 9,277
  • 40
  • 37
  • 54
Jay Bro
  • 15
  • 5

3 Answers3

1

You could use a where condition for check the 90 time_min for delete

  delete from my_table 
  where time_min  > 90 
ScaisEdge
  • 129,293
  • 10
  • 87
  • 97
1

try this-

 DELETE FROM `table_name` where table_name.time_min>90
Masivuye Cokile
  • 4,729
  • 3
  • 18
  • 34
coder001
  • 112
  • 7
0

Use WHERE Clause condition on column in the query

DELETE FROM 'table_name' tbn WHERE tbn.time_min>90
Rahul
  • 1,587
  • 1
  • 8
  • 18
phpforcoders
  • 316
  • 1
  • 9