# FETCH

The `FETCH` clause is used to fetch records from a table.

The `FETCH` clause is used to retrieve related records or data from other tables in a single query. This is particularly useful when you want to gather data that is linked through relationships ([record links](/docs/reference/query-language/language-primitives/record-links.md) or [graph edges](/docs/reference/query-language/statements/relate.md)) without having to perform multiple separate queries.

The `FETCH` clause predates and is functionally identical to the [`ALL`](/docs/reference/query-language/language-primitives/idioms.md#all-elements) idiom which is used by appending a `.*` to a related record.

## Example usage

Suppose you have a person table and a post table, where each post is related to a person. You can use the FETCH clause to retrieve a person along with their posts in a single query:

```surql
-- Using FETCH syntax
SELECT * FROM person FETCH posts;

-- Using .*
SELECT *, posts.* FROM person;
```

In this example, `posts` would be a related field in the `person` table that links to the `post` table. The `FETCH` clause allows you to retrieve all posts associated with each person in the result set.

Overall, the `FETCH` clause in SurrealQL is a powerful tool for optimising data retrieval and simplifying query logic when working with related data.

The following example shows querying using `FETCH` or `.*` compared to selecting individual fields of a related record.

```surql
-- Fetch all fields from author and category
SELECT
	title,
	category,
	author
FROM article
FETCH author, category;

-- Use .* syntax to do the same
SELECT
	title,
	category.*,
	author.*
FROM article;
```

## Without the `FETCH` clause

```surql
-- Access single field from author link
SELECT
	title,
	category,
	author.full_name AS author_name
FROM article;
```
