#### This Page

# `lektor.db.``Query`

The query class is used to filter queries to the database. It's available through either the Pad or through things like the children property of records.

Most operations on a query object return another one which will return a more filtered result.

## Example

Here a basic example of how to filter something in a template:

    <ul>
    {% for item in this.children.filter(F.status == 'published') %}
      <li>{{ item.title }}</li>
    {% endfor %}
    </ul>

#### all()

Returns all matching records as list.

#### count()

Counts the total number of records a query matches.

#### distinct()

Returns the set of unique values for a field.

#### filter()

Filters a query down by an expression.

#### first()

Returns the first matching record.

#### get()

Looks up an item by ID.

#### include_hidden()

Changes the query so that it includes or does not include hidden records.

#### include_undiscoverable()

Controls what happens to records that are not discoverable.

#### limit()

Limits the total number of items returned.

#### offset()

Skips a certain number of records.

#### order_by()

Changes the ordering of the query.

#### request_page()

Requests a specific page from a pagination.

#### self

Returns the item at the query itself.

## Comments