# Query Favorite & Keyword Binding

There are some queries you want to reuse in different contexts or with different objects quite frequently. You can add it to favorite and assign a keyword for reference and call it quickly using that keyword later.

![](https://2743975646-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LriZ7WXXZykpg6_MQsw%2F-LrtXG4_4-yupXPS_pdN%2F-Lru25T4UR0_Fz1vBoZD%2Ffavorite.gif?alt=media\&token=67741b9b-6a2b-4eb1-8a44-76131bff5f83)

## **New favorite query**

**To add a new favorite query:**

* Right click on the **Favorite** section on the left sidebar.
* Choose **`New`** > **`File...`**
* From the popup editor window, name the query and its binding keyword
* Press **`⌘ + S`** to save the changes and then close the window.

**To add a query to favorite from the Editor or from the History:**

* Select the query from the editor (you can also choose from **History** tab)
* Right-click and choose **`Add to favorite`**
* From the popup editor window, name the query and its binding keyword
* Press **`⌘ + S`** to save the changes and then close the window.

Later, when you want to use a favorite query, type the assigned keyword and TablePlus will insert that query into the editor.

## **Use a favorite query**

**To use a query from Favorite from the Editor,** type the assigned keyword and hit Enter, the query will be inserted.

Or you can find the query in the Favorite and choose:

* **`Run`** to execute the query in a new tab
* **`Copy`** to copy the query to the clipboard, you can also select it and use shortcut key **`⌘ + C`** then paste it to the Query Editor.
* **`Import...`** to use the favorite query via the SQL Import Wizard.
* **`Open in anew tab`** to open Query Editor in a new tab and insert the query into it.
* **`Insert to SQL Editor`** to insert the query into the current Query Editor.

To open a favorite query in a separate SQL Viewer and edit its code, name, and keyword, right click on the query and choose **`Edit/Rename`**. When the edit is done, press **`⌘ + S`** to save it.

{% hint style="info" %}
To avoid auto saving queries while editing it in the Query Editor, go to Preferences (Cmd + ,) and unselect the **`Auto save queries while editing`** option in the General tab.&#x20;

You can also change this via the dropdown menu at the bottom of the left sidebar
{% endhint %}

## **Delete favorite query**

**To delete a query from Favorite**, right click on the query and choose **`Delete`**

## **Show query file location**&#x20;

**To see the location of the SQL file that contains query**, right click on the query and choose **`Show in Finder`**

## Favorite query folder

Favorite queries can be grouped into folders.

**To create a new favorite folder**, you can either:

* Right click on the Favorite section and choose **`New`** > **`Folder...`**
* Or right click on the Favorite section and choose **`New`** > **`Add Folder to Favorites...`**, then select the query folder on your computer to import into Favorite.

**To add a favorite query into a folder**, drag and drop the query to the folder you want.

**To rename a favorite folder**, right click on the folder and choose **`Edit/Rename`**

**To delete a favorite folder**, right click on the folder and choose **`Delete`**

## Customize Favorite

By default, when double click on the favorite query, TablePlus runs the query. You can change this default behaviour using the dropdown menu at the bottom of the left sidebar.&#x20;

If you enable **`Double click to Insert Favorite`**, when you double on a favorite query, TablePlus insert it to the current tab of Query Editor instead.

![](https://2743975646-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LriZ7WXXZykpg6_MQsw%2F-Ls2k3EOavGU_TTE12OO%2F-Ls2kv1-DUDCQ98v3w8c%2Fcustomize%20favorite.png?alt=media\&token=e231b0f6-9ca4-4fc6-bb80-4d96702f9232)

You can select/unselect **`Auto save Favorite`** to enable/disable autosave while editing favorite queries
