# Raw Expressions

Raw expressions are the qb escape hatch.  While qb strives to provide ways to execute the majority of queries, you will occasionally need to provide raw sql values that are not processed by qb.  These SQL snippets are called `raw` or `Expressions` in qb.

{% hint style="warning" %}
`raw` expressions are useful, but shoud be used only if there is not another way to accomplish the same action using other qb methods.  This is because a `raw` expression has the potential to use syntax specific to one database grammar or another, preventing you from easily switching from one grammar to another, one of the major benefits of using qb.
{% endhint %}

The first way to retrieve an `Expression` is to call the `raw` method on the `QueryBuilder` object.

## raw

| Name | Type   | Required | Default | Description                              |
| ---- | ------ | -------- | ------- | ---------------------------------------- |
| sql  | string | true     |         | The raw sql to wrap up in an Expression. |

The sql snippet passed to `raw` is not processed by qb at all.  With that in mind, it is important to follow all best practices and security recommendations with the sql you use with `raw`.

{% code title="QueryBuilder" %}

```javascript
query.from( "users" ).select( query.raw( "MAX(created_date)" ) );
```

{% endcode %}

{% code title="MySQL" %}

```sql
SELECT MAX(created_date) FROM `users`
```

{% endcode %}

Expressions can be passed to most qb methods, like `select`, `from`, `where`, or `orderBy`, among others.  Additionally, qb provides some convenience methods to add raw values in different parts of the query:

* [selectRaw](/8.9.0/query-builder/building-queries/selects.md#get-3)
* [fromRaw](/8.9.0/query-builder/building-queries/from.md#get-2)
* [joinRaw](/8.9.0/query-builder/building-queries/joins.md#joinraw)
* [leftJoinRaw](/8.9.0/query-builder/building-queries/joins.md#leftjoinraw)
* [rightJoinRaw](/8.9.0/query-builder/building-queries/joins.md#rightjoinraw)
* [crossJoinRaw](/8.9.0/query-builder/building-queries/joins.md#crossjoinraw)
* [whereRaw](/8.9.0/query-builder/building-queries/wheres.md#whereraw)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://qb.ortusbooks.com/8.9.0/query-builder/building-queries/raw-expressions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
