# sql_models.yaml

You can write queries within the YAML file or in standalone `sql` files and reference them in the `sql_template` model. They have the same keys as an [`input` model]({{< ref "profiles/dev-docs/inputs-yaml/" >}}).

This data is saved in the `model` folder of a Profiles project, along with any referenced `sql` files.

```yaml
models:
    - name: name_of_sql_model       
      model_type: sql_template      
      model_spec:
          <model-spec>
```

| Key | Description |
| :------------ | :----------- |
| `name` <br/> <span style="color: #4D4DFF;font-size:12px;">Required</span> | SQL model name. |
| `model_type` <br/> <span style="color: #4D4DFF;font-size:12px;">Required</span> | Model type - set it to `sql_template`. |
| `model_spec` <br/> <span style="color: #4D4DFF;font-size:12px;">Required</span> | Model configuration. See [SQL Model Spec]({{< ref "profiles/dev-docs/sql-model-yaml/sql-model-config.md" >}}) for more information. |

## Example

```yaml
models:
    - name: 
      model_type: sql_template
      model_spec:
          single_sql: |
              {% with input_table = this.DeRef("inputs/rsIDS) %}
                select 
                  id,
                  first,
                  last
                from
                  {{input_table}}
                where
                  id_type = 'email'
              {% endwith %}
          ids:
              select: "id"
              type: user_id
              entity: user
```

