SQL Console

[Edit this page](https://github.com/ClickHouse/clickhouse-docs/blob/main/docs/integrations/sql-clients/sql-console.md)

SQL console is the fastest and easiest way to explore and query your databases in ClickHouse Cloud. You can use the SQL console to:

- Connect to your ClickHouse Cloud Services
- View, filter, and sort table data
- Execute queries and visualize result data in just a few clicks
- Share queries with team members and collaborate more effectively.

## Exploring tables[​](#exploring-tables "Direct link to Exploring tables")

### Viewing table list and schema info[​](#viewing-table-list-and-schema-info "Direct link to Viewing table list and schema info")

An overview of tables contained in your ClickHouse instance can be found in the left sidebar area. Use the database selector at the top of the left bar to view the tables in a specific database

Tables in the list can also be expanded to view columns and types

### Exploring table data[​](#exploring-table-data "Direct link to Exploring table data")

Click on a table in the list to open it in a new tab. In the Table View, data can be easily viewed, selected, and copied. Note that structure and formatting are preserved when copy-pasting to spreadsheet applications such as Microsoft Excel and Google Sheets. You can flip between pages of table data (paginated in 30-row increments) using the navigation in the footer.

### Inspecting cell data[​](#inspecting-cell-data "Direct link to Inspecting cell data")

The Cell Inspector tool can be used to view large amounts of data contained within a single cell. To open it, right-click on a cell and select 'Inspect Cell'. The contents of the cell inspector can be copied by clicking the copy icon in the top right corner of the inspector contents.

## Filtering and sorting tables[​](#filtering-and-sorting-tables "Direct link to Filtering and sorting tables")

### Sorting a table[​](#sorting-a-table "Direct link to Sorting a table")

To sort a table in the SQL console, open a table and select the 'Sort' button in the toolbar. This button will open a menu that will allow you to configure your sort. You can choose a column by which to sort and configure the ordering of the sort (ascending or descending). Select 'Apply' or press Enter to sort your table

The SQL console also allows you to add multiple sorts to a table. Click the 'Sort' button again to add another sort. Note: sorts are applied in the order that they appear in the sort pane (top to bottom). To remove a sort, simply click the 'x' button next to the sort.

### Filtering a table[​](#filtering-a-table "Direct link to Filtering a table")

To filter a table in the SQL console, open a table and select the 'Filter' button. Just like sorting, this button will open a menu that will allow you to configure your filter. You can choose a column by which to filter and select the necessary criteria. The SQL console intelligently displays filter options that correspond to the type of data contained in the column.

When you're happy with your filter, you can select 'Apply' to filter your data. You can also add additional filters as shown below.

Similar to the sort functionality, click the 'x' button next to a filter to remove it.

### Filtering and sorting together[​](#filtering-and-sorting-together "Direct link to Filtering and sorting together")

The SQL console allows you to filter and sort a table at the same time. To do this, add all desired filters and sorts using the steps described above and click the 'Apply' button.

### Creating a query from filters and sorts[​](#creating-a-query-from-filters-and-sorts "Direct link to Creating a query from filters and sorts")

The SQL console can convert your sorts and filters directly into queries with one click. Simply select the 'Create Query' button from the toolbar with the sort and filter parameters of your choosing. After clicking 'Create query', a new query tab will open pre-populated with the SQL command corresponding to the data contained in your table view.

Note

Filters and sorts aren't mandatory when using the 'Create Query' feature.

You can learn more about querying in the SQL console by reading the (link) query documentation.

## Creating and running a query[​](#creating-and-running-a-query "Direct link to Creating and running a query")

### Creating a query[​](#creating-a-query "Direct link to Creating a query")

There are two ways to create a new query in the SQL console.

- Click the '+' button in the tab bar
- Select the 'New Query' button from the left sidebar query list

### Running a query[​](#running-a-query "Direct link to Running a query")

To run a query, type your SQL command or commands into the SQL Editor and click the 'Run' button or use the shortcut `cmd / ctrl + enter`. To write and run multiple commands sequentially, make sure to add a semicolon after each command.

Query Execution Options
By default, clicking the run button will run all commands contained in the SQL Editor. The SQL console supports two other query execution options:

- Run selected commands
- Run command at the cursor

To run selected commands, highlight the desired command or sequence of commands and click the 'Run' button (or use the `cmd / ctrl + enter` shortcut). You can also select 'Run selected' from the SQL Editor context menu (opened by right-clicking anywhere within the editor) when a selection is present.

Running the command at the current cursor position can be achieved in two ways:

- Select 'At Cursor' from the extended run options menu (or use the corresponding `cmd / ctrl + shift + enter` keyboard shortcut

- Selecting 'Run at cursor' from the SQL Editor context menu

Note

The command present at the cursor position will flash yellow on execution.

### Canceling a query[​](#canceling-a-query "Direct link to Canceling a query")

While a query is running, the 'Run' button in the Query Editor toolbar will be replaced with a 'Cancel' button. Simply click this button or press `Esc` to cancel the query. Note: Any results that have already been returned will persist after cancellation.

### Saving a query[​](#saving-a-query "Direct link to Saving a query")

If not previously named, your query should be called 'Untitled Query'. Click on the query name to change it. Renaming a query will cause the query to be saved.

You can also use the save button or `cmd / ctrl + s` keyboard shortcut to save a query.

## Using GenAI to manage queries[​](#using-genai-to-manage-queries "Direct link to Using GenAI to manage queries")

This feature allows you to write queries as natural language questions and have the query console create SQL queries based on the context of the available tables. GenAI can also help you debug your queries.

For more information on GenAI, checkout the [Announcing GenAI powered query suggestions in ClickHouse Cloud blog post](https://clickhouse.com/blog/announcing-genai-powered-query-suggestions-clickhouse-cloud).

### Table setup[​](#table-setup "Direct link to Table setup")

Let's import the UK Price Paid example dataset and use that to create some GenAI queries.

1. Open a ClickHouse Cloud service.
2. Create a new query by clicking the *+* icon.
3. Paste and run the following code:

   ```
   CREATE TABLE uk_price_paid
   (
       price UInt32,
       date Date,
       postcode1 LowCardinality(String),
       postcode2 LowCardinality(String),
       type Enum8('terraced' = 1, 'semi-detached' = 2, 'detached' = 3, 'flat' = 4, 'other' = 0),
       is_new UInt8,
       duration Enum8('freehold' = 1, 'leasehold' = 2, 'unknown' = 0),
       addr1 String,
       addr2 String,
       street LowCardinality(String),
       locality LowCardinality(String),
       town LowCardinality(String),
       district LowCardinality(String),
       county LowCardinality(String)
   )
   ENGINE = MergeTree
   ORDER BY (postcode1, postcode2, addr1, addr2);
   ```

   This query should take around 1 second to complete. Once it's done, you should have an empty table called `uk\_price\_paid.
4. Create a new query and paste the following query: