# Update Matching Rows

> Find rows matching a query and update them all with the specified values.

- ID: `db_update_matching_rows`
- Type: Block
- Category: [Databases](https://inventor.bot/docs/reference/blocks/databases.md)

- Database columns are extra inputs/outputs named `dbcol_<column name>`.

**Inputs**

| Name | Required | Description | Value |
| --- | --- | --- | --- |
| `database_id` | yes | Select the database to update. |  |
| `limit` |  | Maximum number of rows to update (default: 100, max: 1000). | e.g. `"100"` |
| `update_mode` |  | How to handle empty fields: keep existing values or replace with empty. | `"Keep existing values"`, `"Replace all values"` |
| `query_json` |  | Define filters to find the rows to update. | JSON text, format below |

**`query_json` format**: JSON text of type `DatabaseQuery`. Fields marked `?` are optional.

```ts
type DatabaseQuery = {
	where?: FilterGroup
	sort?: SortClause[]
	limit?: number
	offset?: number
}

type FilterGroup = {
	logic: string // "and" or "or"
	conditions: FilterCondition[]
}

type FilterCondition = {
	type: string // "comparison" or "group"
	columnId?: string // comparison only
	operator?: string // comparison only: eq, neq, gt, gte, lt, lte, contains, not_contains, starts_with, ends_with, is_empty, is_not_empty
	value?: string // comparison only
	group?: FilterGroup // group only
}

type SortClause = {
	columnId: string
	direction: string // "asc", "desc" or "random"
}
```

**Outputs**

| Name | Description | Value |
| --- | --- | --- |
| `updated_count` | The number of rows that were updated. | e.g. `"5"` |

**Example**

```go
matchingRows := db_update_matching_rows(Args{database_id: "..."})
send_text_message(Args{
	channel_id:      trigger.channel_id,
	message_content: "Updated Count: " + matchingRows.updated_count,
})
```