# Lesson 8: Composing clauses

In this lesson, we’ll learn how we can compose clauses to build queries into longer **pipelines**, and to to retrieve results in more useful structures using advanced `fetch` clause functionality.

We’ll see how to perform **aggregations**, and finally how we can **sort** and **paginate** the results returned.

## [](#_recommended_prerequisites)Recommended prerequisites

*   You should complete [Lesson 7](../7-understanding-query-patterns/index.md) before starting this lesson.
    

## [](#_lesson_contents)Lesson contents

[Lesson 8.1: Chaining clauses](8.1-chaining-clauses/index.md)

Learn how to chain clauses

[Lesson 8.2: Subqueries](8.4-subqueries/index.md)

Learn how to group results using subqueries.

[Lesson 8.3: Aggregations](8.2-aggregations/index.md)

Learn how to aggregate results using subqueries.

[Lesson 8.4: Sorting and pagination](8.3-sorting-and-pagination/index.md)

Learn how to sort and paginate query results.

## [](#_typeql_keywords_introduced)TypeQL keywords introduced

*   `reduce`
    
*   `count`
    
*   `sum`
    
*   `max`
    
*   `min`
    
*   `mean`
    
*   `median`
    
*   `std`
    
*   `sort`
    
*   `asc`
    
*   `desc`
    
*   `limit`
    
*   `offset`
    

[Summary](../7-understanding-query-patterns/summary/index.md) [Chaining clauses](8.1-chaining-clauses/index.md)

[Edit on GitHub](https://github.com/typedb/typedb-docs/edit/3.x-development/academy/modules/ROOT/pages/8-composing-clauses/index.adoc) Edit this page on GitHub.