> ## Documentation Index
> Fetch the complete documentation index at: https://forest-chore-open-api.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Creating segments

> Create and manage segments through the Forest UI, no code required

A **segment** is a saved filter that gives you a dedicated tab on a collection, showing only the records that match specific conditions.

For code-based segments, see [Code-based segments](/product/process/segments/smart-segments/overview).

## Create a segment

1. Enable **Layout Editor** mode (top right of your screen)
2. Click the **⚙️ cog icon** next to the collection you want to edit
3. Go to the **Segments** tab
4. Click **"Create your first segment"** (or **"+ New segment"** if you already have some)
5. Give your segment a **name**
6. Add one or more **filters**
7. Optionally adjust the **sort field and order**
8. Save

<Warning>
  Newly created segments are **disabled** by default. Enable them from the Segments tab in Layout Editor mode.
</Warning>

## Reorder segments

Use the Layout Editor to drag and drop segments into the order that matches your workflow.

## SQL Query segments

For advanced filtering, create a segment using a raw SQL query.

<Info>
  To enable SQL Query segments in back-end v2, your developers need to add a connection name to the datasources on which you want to run live queries.
</Info>

<Warning>
  SQL Query mode is only available for SQL databases. For security reasons, only `SELECT` queries are allowed.
</Warning>

Switch to **Query** mode, type your SQL query, and save. The query must return the **primary key** column of the collection.

```sql theme={null}
SELECT t.id FROM transactions t
JOIN companies beneficiary ON t.beneficiary_company_id = beneficiary.id
JOIN companies emitter ON t.emitter_company_id = emitter.id
WHERE beneficiary.headquarter ILIKE '%United States%'
  AND emitter.headquarter ILIKE '%United States%'
```

<Info>
  To query across multiple databases in PostgreSQL, you can use the [dblink function](https://www.postgresql.org/docs/current/contrib-dblink-function.html).
</Info>
