# SQL

SQL in blup is similar to a traditional SQL editor in the sense, that in SQL you can manage, and edit your SQL queries and, through SQL query you can modify data from the tables present in Sheets.

The SQL consists of mainly 3 sections:

* **SQL Queries View**
* **SQL Bar**
* **SQL Editor**

<figure><picture><source srcset="https://4209426742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Me1x4TD1HxodVbK1aDe%2Fuploads%2FNaQyKeAVOo0rCwtJnP93%2Flight%20mode.png?alt=media&#x26;token=2f2306d4-0cf6-4385-9382-90bb69ca4964" media="(prefers-color-scheme: dark)"><img src="https://4209426742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Me1x4TD1HxodVbK1aDe%2Fuploads%2FQA73RFziidTptHPKpEBm%2Fdark%20mode.png?alt=media&#x26;token=ee77175e-16d1-4920-b09b-d3ab5a2b5fc8" alt=""></picture><figcaption><p>SQL</p></figcaption></figure>

### **SQL Queries View**

**SQL Queries View** consists of all **SQL** **Queries** that you have created. This mainly consists of three columns, the **Name** of the query, the **Description** of the query, and the **Last Modified** date of the query.

You can select any query by checking the check box on the left side of each query entry and perform operations like edit or delete.

This View helps in managing all SQL queries you have made, this can come in handy if you have a large project.

<figure><picture><source srcset="https://4209426742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Me1x4TD1HxodVbK1aDe%2Fuploads%2FkchO6kiwBXaq6Rcu9HDI%2FSQL%20Queries%20View%20Dark.png?alt=media&#x26;token=1e72abb0-c1ca-4a92-92b3-1f10a1509300" media="(prefers-color-scheme: dark)"><img src="https://4209426742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Me1x4TD1HxodVbK1aDe%2Fuploads%2FODyODk7FcILvhQcrgZ6g%2FSQL%20Queries%20View%20Light.png?alt=media&#x26;token=db9c6713-c694-4d95-a279-607c43df0f53" alt="SQL Queries View"></picture><figcaption><p>SQL Querues View</p></figcaption></figure>

### SQL Bar

The **SQL Bar** includes several buttons designed to help you efficiently manage SQL queries. These buttons serve various purposes, such as refreshing all queries and editing query details. Let’s explore them one by one! 😊

<figure><picture><source srcset="https://4209426742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Me1x4TD1HxodVbK1aDe%2Fuploads%2FfWjH0KgGWuxkTIwSxREk%2FScreenshot%202024-02-14%20at%2011.14%202.png?alt=media&#x26;token=91594445-8d6d-4e67-aecf-966a2e7518ee" media="(prefers-color-scheme: dark)"><img src="https://4209426742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Me1x4TD1HxodVbK1aDe%2Fuploads%2Fwcy6pFOH66ECtm9x5575%2FScreenshot%202024-02-14%20at%2011.12%203.png?alt=media&#x26;token=cd4e6b35-6594-4e38-a287-eb527124b88b" alt=""></picture><figcaption></figcaption></figure>

**Refresh Button**

This button is used to refresh all SQL queries.

<figure><picture><source srcset="https://4209426742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Me1x4TD1HxodVbK1aDe%2Fuploads%2Fji9QM3OXpmHaYTltqxAf%2Freload_queries_dark.gif?alt=media&#x26;token=b0ba600a-f799-41b6-9866-73d6f72b32f6" media="(prefers-color-scheme: dark)"><img src="https://4209426742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Me1x4TD1HxodVbK1aDe%2Fuploads%2Fov5aE34Ul1cl872HpcNy%2Freload_queries_ligh.gif?alt=media&#x26;token=240eafd3-e485-4b66-8fd5-037ba771297b" alt="Reload Queries"></picture><figcaption><p>Refresh Button</p></figcaption></figure>

#### **Search Button**

On enabling this button, a search bar will appear below the **Name**, **Description,** and **Last Modified** of your queries. The SQL queries are stored in a table which is explained below, so that you can search a query based on the **Name or** **Description or Last Modified** that you provide in the search bar.

<figure><picture><source srcset="https://4209426742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Me1x4TD1HxodVbK1aDe%2Fuploads%2FK2YyOgGGeOtHz33nw7xx%2Fsearch_query_dark.gif?alt=media&#x26;token=19cfac85-dc7b-4dff-a3ee-06e5826a6d92" media="(prefers-color-scheme: dark)"><img src="https://4209426742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Me1x4TD1HxodVbK1aDe%2Fuploads%2FBn8WV9jiY4CehA6EU2Xu%2Fsearch_query_light.gif?alt=media&#x26;token=7d1dc5fa-46cc-404f-a08e-46e2f5503133" alt="Search Queries"></picture><figcaption><p>Search Button</p></figcaption></figure>

#### **Add Query Button**

**The Add Query Button** is used to create a new query.

On clicking this button a pop-up will appear asking you to enter the **Name** and **Description** of the query which you want to make.

This is done so that you can manage different queries and keep track of what the particular query does in writing the description.

<figure><picture><source srcset="https://4209426742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Me1x4TD1HxodVbK1aDe%2Fuploads%2F3WrhouZAwD1RjVwFKxdn%2Fadd_query_dark.gif?alt=media&#x26;token=2b53ee20-371a-4355-a77e-927d0810d1b8" media="(prefers-color-scheme: dark)"><img src="https://4209426742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Me1x4TD1HxodVbK1aDe%2Fuploads%2FWquhARtnygNKLZz200O7%2Fadd_query_light.gif?alt=media&#x26;token=664bf49b-63db-4ac6-9719-a04e68c80d12" alt="Add Query"></picture><figcaption><p>Add Query Button</p></figcaption></figure>

#### **Delete Query Button**

**The Delete Query** button is used to delete a query, this button is disabled by default if no query is selected or present.

Firstly, select a query to delete it.

<figure><picture><source srcset="https://github.com/BlupGithub/blup-docs/blob/main/wiki/backend/broken-reference" media="(prefers-color-scheme: dark)"><img src="https://4209426742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Me1x4TD1HxodVbK1aDe%2Fuploads%2FX33lmQubKtjiQGxOwgoD%2Fdelete_query_light.gif?alt=media&#x26;token=3a74688a-5b20-4272-b277-0b2bf37ea8f3" alt="Delete Query"></picture><figcaption><p>Delete Query</p></figcaption></figure>

> Note: You can also delete multiple queries by selecting them.

#### **Edit Query Button**

**The Edit Query** button is used to edit a query, the **Edit Query** is disabled by default if no query is selected.

On clicking **Edit Query,** a pop-up will appear containing the **Name** and **Description** of the query that you can edit and save.

<figure><picture><source srcset="https://4209426742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Me1x4TD1HxodVbK1aDe%2Fuploads%2FCsXhVWIMbIXzmz2sU16J%2Fedit_query_dark.gif?alt=media&#x26;token=0247c109-537a-4b08-9847-b1c523f8316a" media="(prefers-color-scheme: dark)"><img src="https://4209426742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Me1x4TD1HxodVbK1aDe%2Fuploads%2F3kG9b5fJOWL3125J6crp%2Fedit_query_light.gif?alt=media&#x26;token=f36d6f08-146e-43cc-b87f-3eb4f2f1839d" alt="Edit Query"></picture><figcaption><p>Edit Query</p></figcaption></figure>

#### **Filter Button**

On enabling the **Filter Button**, a filter option will appear on the right side of all the columns present in the **SQL Queries View**, where you can apply the filters on the data present. There are some filter options like:

* A-Z / Z-A for Text-type columns - sort by ascending or descending for text
* Newest First / Oldest First for Date Time type columns - sort by datetime.

<figure><picture><source srcset="https://4209426742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Me1x4TD1HxodVbK1aDe%2Fuploads%2FP96WluCM2kBaHoRRwHDW%2Ffilter_query_dark-ezgif.com-video-speed.gif?alt=media&#x26;token=b6cceb7c-876e-425f-804e-91dcaa6cbbdd" media="(prefers-color-scheme: dark)"><img src="https://4209426742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Me1x4TD1HxodVbK1aDe%2Fuploads%2F2T9dbVKPrmTyDXOHqw7Z%2Ffilter_query_light-ezgif.com-crop-video.gif?alt=media&#x26;token=6b72d6a2-9a13-4deb-8139-becc93ee20d8" alt=""></picture><figcaption><p>Filter Queries</p></figcaption></figure>

**SQL Editor**

The **SQL Editor** is one of the most important parts of the SQL section. Here you can write your SQL queries and test them. The query that you have clicked from the SQL query table is shown here.

<figure><img src="https://4209426742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Me1x4TD1HxodVbK1aDe%2Fuploads%2FjNRAkjgdwvrIupFjlJND%2Fsql_editor.png?alt=media&#x26;token=0850bd5b-2ddd-461c-8c05-4aebbb962cd9" alt="sql-editor"><figcaption><p>SQL Editor</p></figcaption></figure>

The SQL Editor has mainly 4 parts:

### **1.**  SQL Editor **Top Bar**

The top bar consists of three things :

1\) **SQL Query Name** - Name of the query that is opened.

2\) **Run SQL Button** - This is used to run the SQL query, along with this you can also configure a test event by clicking the dropdown arrow from the Run SQL button.

3\) **Save SQL Button** - This is used to save an edited SQL query, you need to run the query or press this button in order to save the query you have written.

<figure><img src="https://4209426742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Me1x4TD1HxodVbK1aDe%2Fuploads%2FDdJdcx6ldN8EOLv80ops%2Fsql_top_bar.png?alt=media&#x26;token=22ad7e0e-cf6c-464c-89e2-f0866699854b" alt="sql-editor-top-bar"><figcaption><p>SQL Editor Top Bar</p></figcaption></figure>

### ***2.  Editor***

Here you can write your SQL queries, this works as a traditional code editor where you can copy, cut, and paste your code along with SQL syntax highlighting

<figure><img src="https://4209426742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Me1x4TD1HxodVbK1aDe%2Fuploads%2FWrWEHAy55BkJxtisabzk%2Fsql_editor.gif?alt=media&#x26;token=7a8479c7-c2aa-4cb4-9a70-c807ae0cad25" alt="sql-editor"><figcaption><p>sql-editor</p></figcaption></figure>

### ***3.  QT AI Prompt Bar***

The SQL section has an AI-powered editor called QT AI, where you can write a prompt and the respective SQL query will be generated for you. For example, you can give a prompt "Give me all the phone numbers from the user table", it AI automatically recognizes the context and gives you a SELECT query.

<figure><img src="https://4209426742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Me1x4TD1HxodVbK1aDe%2Fuploads%2Fu2lkKft8hcmzIILMDz6v%2Fqt-ai-prompt.png?alt=media&#x26;token=9aca136f-2d32-4c37-8bd9-95dfbd218098" alt="qt-ai-prompt"><figcaption><p>qt-ai-prompt</p></figcaption></figure>

### ***4.  Output Section***

This is where you get the execution results of your sql query, it shows you the error encountered if any, or the success result obtained from running the query.

<figure><img src="https://4209426742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Me1x4TD1HxodVbK1aDe%2Fuploads%2FhiGRO3D6Rjus7t7OrzXm%2Fsql-result.png?alt=media&#x26;token=0549a1b0-8d9a-4386-9ab8-b63c5f2d4855" alt="sql-output"><figcaption><p>sql-output</p></figcaption></figure>

## Music to go with.

{% embed url="<https://open.spotify.com/playlist/0vvXsWCC9xrXsKd4FyS8kM?si=2c7f55bd3f944878>" %}
Lofi music
{% endembed %}
