--- title: "system.db.runScalarQuery" description: "Runs a query against a database connection just like the runQuery function, but only returns the value from the first row and column." --- # system.db.runScalarQuery > Runs a query against a database connection just like the runQuery function, but only returns the value from the first row and column. This function is used in **Python Scripting**. ## Description Runs a query against a database connection just like the runQuery function, but only returns the value from the first row and column. If no results are returned from the query, the special value None is returned. ## Client Permission Restrictions [Permission Type](ignition-modules\vision\vision-project-properties\vision-project-properties.md#vision-permissions-properties): Legacy Database Access Client access to this scripting function is blocked to users that do not meet the role/zone requirements for the above permission type. This function is unaffected when run in the Gateway scope. ## Syntax - Gateway `system.db.runScalarQuery(query, database, [tx])` ### Parameters Type | Parameter | Description ------- | ------- | ----- String| `query` | A SQL query that should be designed to return one row and one column. String| `database` | The name of the database connection to execute against. String| `tx` | A transaction identifier. If omitted, the query will be executed in its own transaction. [optional] ### Returns **Object** - The value from the first row and first column of the results. - Returns None if no rows were returned. ### Scope Gateway ## Syntax - Vision and Perspective `system.db.runScalarQuery(query, [database], [tx])` ### Parameters Type | Parameter | Description ------- | ------- | ----- String| `query` | A SQL query that should be designed to return one row and one column. String| `database` | The name of the database connection to execute against. If omitted or "", the project's default database connection will be used. [optional] String| `tx` | A transaction identifier. If omitted, the query will be executed in its own transaction. [optional] ### Returns **Any** - The value from the first row and first column of the results. Returns None if no rows were returned. ### Scope Vision Client, Perspective Session ## Code Examples ```python title="Code Snippet" # This code counts the number of active alarms and acknowledges them all if there is at least one. numAlarms = system.db.runScalarQuery("SELECT COUNT(*) FROM alarmstatus " + "WHERE unacknowledged = 1") if numAlarms > 0: # There are alarms - acknowledge all of them system.db.runUpdateQuery("UPDATE alarmstatus SET unacknowledged = 0") ``` ```python title="Code Snippet" # This code reads a single value from a table and shows it to the user in a popup. level = system.db.runScalarQuery("SELECT Level FROM LakeInfo WHERE LakeId='Tahoe'") system.gui.messageBox("The lake level is: %d feet" % level) ```