

# Get started with the query editor
<a name="sql-query-get-started"></a>

The query editor is where you write SQL, run queries, and visualize results in Amazon SageMaker Unified Studio. This section walks you through opening the editor, understanding the interface, and connecting to your data.

## Prerequisites
<a name="sql-query-prerequisites"></a>

As a member of a Amazon SageMaker Unified Studio project, your IAM role needs the following managed policies:
+ [SageMakerStudioUserIAMConsolePolicy](https://docs.aws.amazon.com/sagemaker-unified-studio/latest/adminguide/security-iam-awsmanpol-SageMakerStudioUserIAMConsolePolicy.html) to sign in and access the project.
+ [SageMakerStudioUserIAMDefaultExecutionPolicy](https://docs.aws.amazon.com/sagemaker-unified-studio/latest/adminguide/security-iam-awsmanpol-SageMakerStudioUserIAMDefaultExecutionPolicy.html) to access data and resources within the project.

If you don't have access, contact your administrator. If you are the administrator who set up the project, you already have the required permissions.

## Open the query editor
<a name="sql-query-open"></a>

1. Go to your project using the project selector at the top of the page.

1. In the left navigation pane, choose **Query Editor**.

The query editor opens with an empty querybook tab.

## Query editor orientation
<a name="sql-query-orientation"></a>

The following screenshot shows the main areas of the query editor interface.

![\[The query editor interface with numbered callouts for the main areas.\]](http://docs.aws.amazon.com/sagemaker-unified-studio/latest/userguide/images/sql-analytics/sql-editor-overview.png)



| \$1 | Element | Description | 
| --- | --- | --- | 
| 1 | Navigation sidebar | Access project tools including Query Editor, Visual ETL, Notebooks, Workflows, and more. | 
| 2 | Panel icons | Switch between the data explorer, file explorer, query history, and scheduled queries views. | 
| 3 | Data explorer | Browse catalogs, connections, and buckets. Search for data assets and add new data sources. | 
| 4 | Querybook tabs | Each tab is a separate querybook. Choose \$1 to create a new one. | 
| 5 | Run all and toolbar | Run all SQL cells in the querybook. Set the default catalog, database, and query engine. | 
| 6 | SQL cell | Write SQL statements here. Each querybook can contain multiple SQL and markdown cells. | 

## Browse data in the data explorer
<a name="sql-query-browse-data"></a>

The data explorer panel on the left side of the query editor shows all data assets available in your project. Use it to find tables, view column names and types, and run sample queries.

![\[The data explorer panel with a catalog expanded to show databases, tables, and columns.\]](http://docs.aws.amazon.com/sagemaker-unified-studio/latest/userguide/images/sql-analytics/sql-data-explorer.png)


To browse your data:

1. In the data explorer, expand a catalog to see its databases.

1. Expand a database to see its tables.

1. Expand a table to see its columns and data types.

Use the search bar at the top of the data explorer to find specific tables or columns by name.

## Connect to a data source
<a name="sql-query-connect"></a>

You can add data sources to the query editor using the **Add** button (\$1) in the data explorer panel.

![\[The Add data source dialog showing three options: create S3 tables catalog, create table, and add S3 location.\]](http://docs.aws.amazon.com/sagemaker-unified-studio/latest/userguide/images/sql-analytics/sql-add-data-source.png)


There are three ways to add a data source:
+ **Create S3 tables catalog**: Create a new catalog for your S3 tables.
+ **Create table**: Upload data files to create a new table.
+ **Add S3 location**: Add an existing S3 location as a data source.

You can also add data sources from the **Connections** page in the left navigation pane. Connections configured there are available across all project tools, including the query editor. For more information, see [Data and catalog connections in IAM-based domains](data-connections-iam-based-domains.md).

## Choose a query engine
<a name="sql-query-engine"></a>

Each querybook uses a single query engine at a time. You can switch engines using the engine selector dropdown in the upper-right corner of the querybook toolbar.

![\[The engine selector dropdown showing Athena and Redshift options.\]](http://docs.aws.amazon.com/sagemaker-unified-studio/latest/userguide/images/sql-analytics/sql-engine-selector.png)


1. Choose the engine selector dropdown in the upper-right corner of the querybook.

1. Choose the query engine you want to use (for example, **Athena (SQL)**).

1. Under **Catalogs**, choose the catalog for your data.

1. Under **Databases**, choose the database you want to query.

1. Choose **Choose** to confirm your selection.

**Note**  
The catalogs and databases available depend on which engine you select. Athena connects to AWS Glue Data Catalog resources, while Redshift connects to Redshift-managed catalogs. To use Amazon Redshift as a query engine, you must first add a Redshift connection to your project from the **Connections** page in the left navigation pane.