# Lesson 3: Reading data

## [](#_fetching_simple_data)[Fetching simple data](../3.1-fetching-simple-data/index.md)

*   **Fetch queries** are used to retrieve data in JSON format. They comprise a `match` clause and `fetch` clause.
    
    ```typeql
    match
    # match clause
    fetch {
      # fetch clause
    };
    ```
    
*   **Variables** are declared with a `$` prefix.
    
*   An `isa` statement is used to specify the **type** of a variable.
    
    ```typeql
    $entity isa entity-type;
    ```
    
*   Data objects can be either **entities** or **relations**.
    
*   Relations have **roles**. An entity that plays a role is a **roleplayer**. All relations must have at least one roleplayer.
    
    ```typeql
    $rel isa relation-type, links ($role-1: $a, $role-2: $b);
    ```
    
*   A `has` statement is used to specify the value of an entity or relation’s **attribute**.
    
    ```typeql
    $entity has attribute-type "attribute value";
    ```
    

## [](#_fetching_polymorphic_data)[Fetching polymorphic data](../3.2-fetching-polymorphic-data/index.md)

*   **Type inference** allows the database to infer the possible types of a variable without having to explicitly specify them all.
    
*   **Inheritance polymorphism** allows us to query data of multiple types through a common **supertype**.
    
*   **Interface polymorphism** allows us to query data of multiple types through a common implemented **interface**: either a role in a relation or ownership of an attribute.
    
*   **Parametric polymorphism** allows us to query data of multiple types through the structure of the data alone. Purely parametric queries can be run on any schema.
    
*   Different types of polymorphism can be combined to produce complex queries.
    

## [](#_using_functions)[Using functions](../3.3-using-functions/index.md)

*   **Functions** allow you to encode modular and re-usuable sub-queries and logic in either queries or even the schema
    

## [](#_fetching_schema_types)[Fetching schema types](../3.4-fetching-schema-types/index.md)

*   Types can be **variablized** in the same way as data instances, by using a variable in place of a **type label** in statements.
    
    ```typeql
    $entity isa $entity-type;
    ```
    
*   An `isa!` statement is used to specify the exact type of a data variable.
    
    ```typeql
    $entity isa! exact-type;
    ```
    
*   A `sub` statement is used to specify a supertype of a type.
    
    ```typeql
    $type sub supertype;
    ```
    
*   A `sub!` statement is used to specify the direct supertype of a type.
    
    ```typeql
    $type sub! direct-supertype;
    ```
    
*   An `owns` statement is used to specify an owner of an attribute type.
    
    ```typeql
    $entity-type owns attribute-type;
    ```
    
*   A `relates` statement is used to specify a role of a relation type.
    
    ```typeql
    relation-type relates $role;
    ```
    
*   A `plays` statement is used to specify a roleplayer of a role.
    
    ```typeql
    $entity-type plays $role;
    ```
    

## [](#_query_validation)[Query validation](../3.5-query-validation/index.md)

*   All queries are **validated** against the schema.
    
*   Running a query that does not conform to the schema will cause an exception to be thrown.
    
*   This is like a compilation failure in a strongly-typed programming language!
    

## [](#_further_learning)Further learning

[Lesson 4: Writing data](../../4-writing-data/index.md)

Learn how to write data to TypeDB, covering insert, delete, and update operations, including polymorphic data writes.

[Reference: Fetch query](../../../typeql-reference/pipelines/fetch/index.md)

Read the Fetch query reference, including syntax, behaviour, and advanced usage.

[Query validation](../3.5-query-validation/index.md) [4\. Writing data](../../4-writing-data/index.md)

[Edit on GitHub](https://github.com/typedb/typedb-docs/edit/3.x-development/academy/modules/ROOT/pages/3-reading-data/summary.adoc) Edit this page on GitHub.