=SQL()
Documentation for =SQL() Custom Formula for Google Sheets
The =SQL()
custom formula allows you to run SQL queries directly in Google Sheets, pulling data from MySQL, SQL Server, or Oracle databases. This can be extremely useful for retrieving, updating, or analyzing your database data directly within your spreadsheet.
How to Use the =SQL() Custom Formula
The =SQL()
formula has the following structure:
Let's break down what each of these parameters means:
dbType: The type of the database. Currently, we support
mysql
,sqlserver
(for Microsoft SQL Server), andoracle
(for Oracle database).host: The host of the database. This is typically a URL or an IP address.
port: The port number for the database. Usually, it's
3306
.dbName: The name of the database.
userName: The username for database authentication.
userPwd: The password for database authentication.
query: The SQL query to interact with the database.
Examples
Example 1: Simple SELECT Query
Let's say you want to pull all data from a table named employees
in your MySQL database. You can use the SELECT
query:
This will pull in all the data from the employees
table in your MySQL database into your Google Sheet.
Example 2: SELECT Query with WHERE Clause
If you want to pull data from a specific row, you can include a WHERE
clause in your query:
This will pull in the data from the row where id
is 1
in the employees
table.
Remember, the =SQL()
formula is a powerful tool that can greatly enhance your Google Sheets' capabilities. However, always ensure you have the necessary permissions to use the database, and be careful not to share sensitive information like usernames and passwords.
Last updated