# Custom SQL queries
You can get your desired data by using a custom SQL query.
# Concept
- Each Restsheet is a database
- When adding a Spreadsheet into the project, each Sheet in the Spreadsheet can be seen as a Table of the database.
- And each column in the Sheet can be treated as column of a table.
Here is an example:
//TODO insert image example sheet
- Sheet "Cities" => Table name is "Cities"
- There are 3 columns:
- "Id": the column data type is
float
- "Name": the column data type is
text
- "CountryCode": the column data type is
text
- "Id": the column data type is
# Write the SQL query
So now it's the same as working on a normal Relational Database, you can write SQL to retrieve your data.
NOTE
The SQL Query is PostgreSQL syntax
Take above table as an example. Let's write a few SQL queries
- Get all the records in the table
SELECT * FROM "Cities";
- Get only city
New York
SELECT *
FROM "Cities"
WHERE "Name" = 'New York';
Of course we can join tables. Let say we have another table called Countries
like this
// TODO add example image
- Get all the cities in
Singapore
SELECT ci.*
FROM "Countries" co
JOIN "Cities" ci ON co."Code" = ci."CountryCode"
WHERE ci."Name" = 'Singapore'
# Get SQL result via REST API
Restsheet allows you to fetch your SQL result via an API. Just switch on the toggle to get the URL endpoint.
Send a GET
HTTP request to get the data.
# Export SQL result to Google Spreadsheet
- After executing the query, you can export the SQL result back to Google Spreadsheet.
- There are two mode:
- Full: Replace all the data of the selected sheet with the SQL result.
- Append: Append the SQL result to the end of the sheet
← REST API