# DetachedSQLProjection()

Besides using it for creating criteria subqueries, Detached Criteria Builder can also be used in conjunction with the new detachedSQLProjection() method to return a projected result based on a subquery. The detachedSQLProjection() method can be called just like any other Criteria Builder projection.

| Transform             | Description                                                                         |
| --------------------- | ----------------------------------------------------------------------------------- |
| detachedSQLProtection | A single or array of DetachedCriteriaBuilders which will return the projected value |

Examples

```javascript
c = newCriteria();
c.withProjections(
        detachedSQLProjection= 
          c.createSubcriteria( "Car", "Car2" )
           .withProjections( count="Car2.Year" )
           .isLT( "Year", javaCast( "int", 2006 ) )
           .isEQ( "CarID", "{alias}.CarID" ),           
        groupProperty="Make"
).list();
```

> **INFO** If you need to use a property from the root entity in one of your criterias, simply prepend the property name with {alias}. **MORE** Notice how a subquery method was not used in this example of the Detached Criteria Builder.


---

# 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://coldbox-orm.ortusbooks.com/criteria-queries/detached-criteria-builder/detachedsqlprojection.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.
