# Delete from where?

**URL:** <https://forum.inductiveautomation.com/t/delete-from-where/1990>\
**Category:** Archived Topics\
**Created:** [June 30, 2010, 2:53pm UTC](https://forum.inductiveautomation.com/t/delete-from-where/1990 "2010-06-30T14:53:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Justin](https://avatars.discourse-cdn.com/v4/letter/j/3ab097/32.png) [@Justin](https://forum.inductiveautomation.com/u/Justin)\
**Post date:** [June 30, 2010, 2:53pm UTC](https://forum.inductiveautomation.com/t/delete-from-where/1990/1 "2010-06-30T14:53:00Z")

</div>

Easy question for most, but I’m not able to find a good example. I am trying to delete a record (row) from a MySql db table using the action script on a button. To keep it simple, the intended row to be deleted will be the selected row. The where clause is dynamic with the selected row so what would work for this?

fpmi.db.runUpdateQuery("DELETE FROM table\_name WHERE Id = ? ")

Thanks!

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [June 30, 2010, 4:44pm UTC](https://forum.inductiveautomation.com/t/delete-from-where/1990/2 "2010-06-30T16:44:29Z")

</div>

I’m assuming you’re selecting a row in a table component, then deleteing that record from the MySQL table…

I just had the same application what I did was add a dyniamic property to the table component that reflected the value in the id column. You can then reference the dynamic property in your script. The reference will look similar to:

```auto
query= "DELETE FROM table_name WHERE Id="+event.source.table.DynamicProperty
fpmi.db.runUpdateQuery(query)
```

---

<div class="post-metadata">

**Author:** ![Justin](https://avatars.discourse-cdn.com/v4/letter/j/3ab097/32.png) [@Justin](https://forum.inductiveautomation.com/u/Justin)\
**Post date:** [June 30, 2010, 5:38pm UTC](https://forum.inductiveautomation.com/t/delete-from-where/1990/3 "2010-06-30T17:38:08Z")

</div>

Thanks for the example, although I get the error listed below.

query = “DELETE FROM 200\_mil\_Thickness WHERE ID =” + event.source.parent.getComponent(‘Table’).value  
fpmi.db.runUpdateQuery(query)

Traceback (innermost last):  
File “event:actionPerformed”, line 1, in ?  
TypeError: **add** nor **radd** defined for these operands

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [June 30, 2010, 5:45pm UTC](https://forum.inductiveautomation.com/t/delete-from-where/1990/4 "2010-06-30T17:45:30Z")

</div>

In concatenation you need to make sure the value is a string. So you can do one of two things:

1. 

```auto
query = "DELETE FROM 200_mil_Thickness WHERE ID = " + str(event.source.parent.getComponent('Table').value) 
```

2. 

```auto
query = "DELETE FROM 200_mil_Thickness WHERE ID = %d" % event.source.parent.getComponent('Table').value 
```

---

<div class="post-metadata">

**Author:** ![Justin](https://avatars.discourse-cdn.com/v4/letter/j/3ab097/32.png) [@Justin](https://forum.inductiveautomation.com/u/Justin)\
**Post date:** [June 30, 2010, 5:49pm UTC](https://forum.inductiveautomation.com/t/delete-from-where/1990/5 "2010-06-30T17:49:51Z")

</div>

Thanks!
