# Select

To begin working with an entity, start with the name of the entity.  Use the `select` method to begin a new query.  This method returns a new instance of the entity class.  When finished, use the `execAsync` method to execute the query in the database and return the records as a [strongly typed version of the WireBootstrap DataTable](/orm/tables-and-views.md#datatable-interface).&#x20;

The example below will return all the records and fields in the `Categories` table in the `Northwind` database.

```javascript
const categoryTable = await Categories.select().execAsync();
```

Note, the `execAsync` method returns a TypeScript `Promise` so the `await` keyword can be used to execute the query asynchronously.

## Fields

To select fields from an entity, use the *\[entity]Field* `enum` parameters on the `select` method.

```javascript
const categoryTable = await Categories.select(
    CategoriesField.CategoryID, 
    CategoriesField.CategoryName
)
.execAsync();
```

The `field` method can also be used to select fields.

```javascript
const categoryTable = await Categories.select()
   .field(CategoriesField.CategoryID)
   .field(CategoriesField.CategoryName)
.execAsync();
```

## Filter

To filter the records returned, use the `eq` method.

```javascript
const categoryTable = await Categories.select()
   .eq(CategoriesField.CategoryName, "Dairy Products") 
.execAsync();
```

## First

To return the first record in a result set, the `execFirstAsync` method can be used instead of the `execAsync` method.

```javascript
const dairyProducts = await Categories.select()
   .eq(CategoriesField.CategoryName, "Dairy Products") 
.execAsyncFirst();
```

Note, unlike the `execAsync` method which returns a data table, this method returns a single `Categories` object.

## Scaler

When selecting a single cell in a query,  the `execScalerAsync` method can be used.

```javascript
const categoryId = await Categories.select(
     CategoriesFields.CategoryID
   )
   .eq(Categories_Field.CategoryName, "Dairy Products") 
.execAsyncScaler();
```

## Order By

To order the records in the result set, use the `orderBy` method.

```javascript
const categoryTable = await Categories.select()
.orderBy(CategoriesField.CategoryName)
.execAsync();
```


---

# 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://docs.wirebootstrap.com/orm/tables-and-views/select.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.
