SQL - getting started

Use SQL to create live connections from your spreadsheets to your databases.

Once established, you have a live connection that can be rerun, refreshed, read from, and written to your SQL database.

You can both read and write to your databases from Quadratic.

Create a connection

Create an SQL connection by pressing / inside a cell. From here, you can access, add, or edit connections. Here are some helpful links to get started, or follow the quick start guide below.

You can also create a connection from the Dashboard > Connections under the Team menu.

Quick start

Create a connection

Step 1: press /

You can create data connections from either your spreadsheets or team's dashboard. From your sheet, press / to open the code selection menu. You'll see both your existing connections and the prompt to manage your connections (create, edit, delete). To get started with creating a connection, choose the Manage connections option.

Step 2: pick the connection type

With the connection management screen open, you can edit an existing connection or create a new one. To create a new connection, select the connection type you want to create.

Step 3: follow the instructions for creating your connection

You can also follow this same create connection process from your team's dashboard under the connections section.

Use connection

Step 1: use your connection

Once your connection has been made you can use your connection directly in the sheet. Open the code cell selection menu with / and select your database from the list - in this example it's named Quadratic Postgres.

You can now query your database from your newly opened SQL code editor. You can view the schema or open the AI assistant in the bottom.

The results of your SQL queries are returned to the sheet, with column 0, row 0 anchored to the cell location.

You can read the data returned from queries in Python, Formulas, Javascript, etc.

Read and manipulate your data returned from SQL to summarize results, create charts, or anything else you might want to use your data for!

🔢 Learn about the SQL AI assistant ->

🔓 Learn about permissions and security ->

Helpful queries

If you need help generating queries, we recommend first trying the AI assistant in your Quadratic code editor - its outputs are very helpful with writing everything from the simplest to most complex SQL queries.

Read data into the spreadsheet

Query all data from single table into the spreadsheet

SELECT * FROM table_name

Query a limited selection (100 rows) from single table into spreadsheet

SELECT * FROM table_name 
LIMIT 100

Query specific columns from single table into the spreadsheet

SELECT column_name1, column_name2 
FROM table_name 
LIMIT 100

Query all unique values in a column

SELECT DISTINCT column_name1 
FROM table_name 
LIMIT 100

Query data conditionally

-- selects 3 specific columns from a table where column1 equals some value
SELECT column1, column2, column3
FROM table_name
WHERE column1 = 'some_value';
-- selects 3 specific columns from a table where column1 equals some value and column2 equals some value 
SELECT column1, column2, column3
FROM table_name
WHERE column1 = 'some_value' AND column2 = 5;

Stuck? The AI assistant in your code editor is ready and waiting to help with your queries.

Last updated