# sql

Runs the specified SQL statement and returns the result as a cursor.

## Syntax

```mongodb
db.runCommand({sql: <string>})
```

## Example

The following example runs an `OPTIMIZE TABLE` command, where **dbTest** and **mycollection** are the names of the database and collection, respectively.

```mongodb
db.runCommand({ sql: "OPTIMIZE TABLE `dbTest`.`mycollection` FULL" });
```

Here's another example that runs a `SELECT` statement:

```mongodb
db.runCommand({ sql: "SELECT * FROM `dbTest`.`mycollection`" });
```

***

Modified at: May 15, 2023

Source: [/cloud/reference/singlestore-kai/singlestore-extension-commands/sql/](https://docs.singlestore.com/cloud/reference/singlestore-kai/singlestore-extension-commands/sql/)

(An index of the documentation is available at /llms.txt)
