# layout: article
title: Queries
description: Harness the power of querying with Appwrite tablesDB. Discover various query options, filtering, sorting, and advanced querying techniques.
Many list endpoints in Appwrite allow you to filter, sort, and paginate results using queries. Appwrite provides a common set of syntax to build queries.

# Query class
Appwrite SDKs provide a `Query` class to help you build queries. The `Query` class has methods for each type of supported query operation.

# Building queries
Queries are passed to an endpoint through the `queries` parameter as an array of query strings, which can be generated using the `Query` class.

...

```server-go
package main

import (
    "fmt"
    "log"

    "github.com/appwrite/sdk-for-go/v7/appwrite"
    "github.com/appwrite/sdk-for-go/v7/query"
)

func main() {
    client := appwrite.NewClient(
        appwrite.WithEndpoint("https://<REGION>.cloud.appwrite.io/v1"),
        appwrite.WithProject("<PROJECT_ID>"),
        appwrite.WithKey("<API_KEY>"),
    )

    tablesDB := appwrite.NewTablesDB(client)

    rows, err := tablesDB.ListRows(
        "<DATABASE_ID>",
        "<TABLE_ID>",
        tablesDB.WithListRowsQueries([]string{
            query.Equal("title", []string{"Avatar", "Lord of the Rings"}),
            query.GreaterThan("year", 1999),
        }),
    )
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("Rows: %+v\n", rows)
}
```

...

```server-php
<?php

use Appwrite\Client;
use Appwrite\Query;
use Appwrite\Services\TablesDB;

$client = new Client();

$client
    ->setEndpoint('https://<REGION>.cloud.appwrite.io/v1')
    ->setProject('<PROJECT_ID>')
    ->setKey('<YOUR_API_KEY>')
;

$tablesDB = new TablesDB($client);

$result = $tables->listRows(
    '<DATABASE_ID>',
    '<TABLE_ID>',
    [
        Query::equal('title', ['Avatar', 'Lord of the Rings']),
        Query::greaterThan('year', 1999)
    ]
);
```

...

```graphql
query {
    tablesListRows(
        databaseId: "<DATABASE_ID>",
        tableId: "<TABLE_ID>"
        queries: [
            "{\"method\":\"equal\",\"column\":\"title\",\"values\":[\"Avatar\",\"Lord of the Rings\"]}",
            "{\"method\":\"greaterThan\",\"column\":\"year\",\"values\":[1999]}"
        ]
    ) {
        total
        rows {
            _id
            data
        }
    }
}
```
```http
GET /v1/tablesdb/<DATABASE_ID>/tables/<TABLE_ID>/rows?queries[]=%7B%22method%22%3A%22equal%22%2C%22column%22%3A%22title%22%2C%22values%22%3A%5B%22Avatar%22%2C%22Lord%20of%20the%20Rings%22%5D%7D&queries[]=%7B%22method%22%3A%22greaterThan%22%2C%22column%22%3A%22year%22%2C%22values%22%3A%5B1999%5D%7D HTTP/1.1
Content-Type: application/json
X-Appwrite-Project: <PROJECT_ID>
```

...

# Query operators
## Select
### Select relationship data
With opt-in relationship loading, you must explicitly select relationship data. This gives you fine-grained control over performance and payload size.

...

#### Get rows without relationships
```server-python
row = tablesDB.get_row(
    database_id='<DATABASE_ID>',
    table_id='<TABLE_ID>',
    row_id='<ROW_ID>',
    queries=[Query.select(["name", "age"])]
)
```

...

```http
GET /v1/tablesdb/<DATABASE_ID>/tables/<TABLE_ID>/rows/<ROW_ID>?queries[]=%7B%22method%22%3A%22select%22%2C%22values%22%3A%5B%22name%22%2C%22age%22%5D%7D HTTP/1.1
Content-Type: application/json
X-Appwrite-Project: <PROJECT_ID>
```

#### Load all relationship data
Use the `*` wildcard to load all fields from related rows:
```client-web
const row = await tablesDB.getRow({
    databaseId: '<DATABASE_ID>',
    tableId: '<TABLE_ID>',
    rowId: '<ROW_ID>',
    queries: [Query.select(['*', 'reviews.*'])]
});
```

...

```http
GET /v1/tablesdb/<DATABASE_ID>/tables/<TABLE_ID>/rows/<ROW_ID>?queries[]=%7B%22method%22%3A%22select%22%2C%22values%22%3A%5B%22%2A%22%2C%22reviews.%2A%22%5D%7D HTTP/1.1
Content-Type: application/json
X-Appwrite-Project: <PROJECT_ID>
{"method":"select","values":["*","reviews.*"]}
```

...

### Use selection patterns
| Pattern | Description | Use case |
| `["field1", "field2"]` | Specific columns only | Minimize response size |
| `["*"]` | All row columns | Get complete row data |
| `["*", "relationName.*"]` | Row + all relationship fields | Load row with complete related data |
| `["field1", "relationName.field2"]` | Specific fields from row and relationships | Precise data loading |
| `["*", "relationName.field1", "relationName.field2"]` | All row fields + specific relationship fields | Partial relationship loading |
| `["relationName.*", "relationName.nestedRelation.*"]` | Nested relationship loading | Load relationships of relationships |

...

# Geo queries and spatial operations
Geo queries enable geographic operations on spatial columns. Coordinates are specified as `[longitude, latitude]` arrays. Distance measurements can be specified in meters or degrees.

...

## Overlaps
```http
{"method":"overlaps","column":"zone","values":[[[-73.9851, 40.7589], [-73.9776, 40.7614], [-73.9733, 40.7505], [-73.9851, 40.7589]]]}
```

...

## Not overlaps
```server-nodejs
const sdk = require('node-appwrite');
sdk.Query.notOverlaps("zone", [[-73.9851, 40.7589], [-73.9776, 40.7614], [-73.9733, 40.7505], [-73.9851, 40.7589]])
```

...

## Touches
```server-nodejs
const sdk = require('node-appwrite');
sdk.Query.touches("boundary", [[-73.9851, 40.7589], [-73.9776, 40.7614], [-73.9733, 40.7505], [-73.9851, 40.7589]])
```

...

## Not touches
```server-nodejs
const sdk = require('node-appwrite');
sdk.Query.notTouches("boundary", [[-73.9851, 40.7589], [-73.9776, 40.7614], [-73.9733, 40.7505], [-73.9851, 40.7589]])
```

...

```http
{"method":"notTouches","column":"boundary","values":[[[-73.9851, 40.7589], [-73.9776, 40.7614], [-73.9733, 40.7505], [-73.9851, 40.7589]]]}
```

...

## Crosses
```server-nodejs
const sdk = require('node-appwrite');
sdk.Query.crosses("route", [[-73.9851, 40.7589], [-73.9776, 40.7614]])
```
```server-python
Query.crosses("route", [[-73.9851, 40.7589], [-73.9776, 40.7614]])
```

...

## Not crosses
```server-nodejs
const sdk = require('node-appwrite');
sdk.Query.notCrosses("route", [[-73.9851, 40.7589], [-73.9776, 40.7614]])
```
```server-python
Query.not_crosses("route", [[-73.9851, 40.7589], [-73.9776, 40.7614]])
```

...

# Complex queries
You can create complex queries by combining AND and OR operations. For example, to find items that are either books under $20 or magazines under $10:

...

This example demonstrates how to combine `OR` and `AND` operations. The query uses `Query.or()` to match either condition: books under $20 OR magazines under $10.
Each condition within the OR is composed of two AND conditions - one for the category and one for the price threshold. The database will return rows that match either of these combined conditions.