# Distinct with Query

> Fetch distinct values for a field based on a query filter using API Maker's g.sys.db.distinctWithQuery method.

Source: https://docs.apimaker.dev/v4/examples/sys/db/distinctQuery.html

> **The code in every language**
>
> Each example is the inside of `main`, written in every [language](https://docs.apimaker.dev/v4/docs/languages/index.html) API Maker runs : pick yours in the tabs, and every page shows it from then on. The types a call takes (`GetAll`, `DeepItem`…) are those of `am` : `from am import GetAll` in Python, `use am::GetAll;` in Rust, `import am.GetAll;` in Java and Kotlin ; PHP and C# have them without an import, Go names them `am.GetAll`.

`g.sys.db.distinctQuery` calls the [distinct with query schema API](https://docs.apimaker.dev/v4/docs/apis-all/schema-apis/auto-generated-schema-based-distinct-with-query-api.html) of any table from your code, with the same headers and query parameters as over HTTP. It returns the data. The whole envelope (`success`, `statusCode`, `data`, `totalCount`, `errors`…) comes back when `true` is passed as the second argument in TypeScript, and through `full` in the other languages : `g.sys.db.full` (`g.Sys.Db.Full` in C# and Go, `$g->sys->db->full` in PHP).

## Simple get distinctWithQuery

**TypeScript**

**Simple distinctWithQuery**

```typescript
let distinctQuery = await g.sys.db.distinctQuery({
    instance: "mysql_8", database: "inventory", collection: "customers",
    distinctField: "first_name"
});
```

**Python**

**Simple distinctWithQuery**

```python
distinct_query = await g.sys.db.distinct_query(
    'mysql_8', 'inventory', 'customers',
    'first_name',
)
```

**PHP**

**Simple distinctWithQuery**

```php
$distinctQuery = $g->sys->db->distinctQuery(
    'mysql_8', 'inventory', 'customers',
    'first_name',
);
```

**C#**

**Simple distinctWithQuery**

```csharp
var distinctQuery = await g.Sys.Db.DistinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name"));
```

**Go**

**Simple distinctWithQuery**

```go
distinctQuery, err := g.Sys.Db.DistinctQuery(am.Distinct{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	DistinctField: "first_name",
})
if err != nil {
	return nil, err
}
```

**Rust**

**Simple distinctWithQuery**

```rust
let distinct_query = g.sys.db.distinct_query(Distinct::new("mysql_8", "inventory", "customers", "first_name"))?;
```

**Java**

**Simple distinctWithQuery**

```java
var distinctQuery = g.sys.db.distinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name"));
```

**Kotlin**

**Simple distinctWithQuery**

```kotlin
val distinctQuery = g.sys.db.distinctQuery(Distinct("mysql_8", "inventory", "customers", "first_name"))
```

## distinctWithQuery with multiple distinctField

**TypeScript**

**distinctWithQuery with multiple distinctField**

```typescript
let distinctQuery = await g.sys.db.distinctQuery({
    instance: "mysql_8", database: "inventory", collection: "customers",
    distinctField: "first_name,last_name"
});
```

**Python**

**distinctWithQuery with multiple distinctField**

```python
distinct_query = await g.sys.db.distinct_query(
    'mysql_8', 'inventory', 'customers',
    'first_name,last_name',
)
```

**PHP**

**distinctWithQuery with multiple distinctField**

```php
$distinctQuery = $g->sys->db->distinctQuery(
    'mysql_8', 'inventory', 'customers',
    'first_name,last_name',
);
```

**C#**

**distinctWithQuery with multiple distinctField**

```csharp
var distinctQuery = await g.Sys.Db.DistinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name,last_name"));
```

**Go**

**distinctWithQuery with multiple distinctField**

```go
distinctQuery, err := g.Sys.Db.DistinctQuery(am.Distinct{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	DistinctField: "first_name,last_name",
})
if err != nil {
	return nil, err
}
```

**Rust**

**distinctWithQuery with multiple distinctField**

```rust
let distinct_query = g.sys.db.distinct_query(Distinct::new("mysql_8", "inventory", "customers", "first_name,last_name"))?;
```

**Java**

**distinctWithQuery with multiple distinctField**

```java
var distinctQuery = g.sys.db.distinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name,last_name"));
```

**Kotlin**

**distinctWithQuery with multiple distinctField**

```kotlin
val distinctQuery = g.sys.db.distinctQuery(Distinct("mysql_8", "inventory", "customers", "first_name,last_name"))
```

## distinctWithQuery with headers

**TypeScript**

**distinctWithQuery with headers**

```typescript
let distinctQuery = await g.sys.db.distinctQuery({
    instance: "mysql_8", database: "inventory", collection: "customers",
    distinctField: "first_name",
    headers: {
        "x-am-response-case": "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    },
});
```

**Python**

**distinctWithQuery with headers**

```python
distinct_query = await g.sys.db.distinct_query(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    headers={
        'x-am-response-case': 'capitalCase',  # noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    },
)
```

**PHP**

**distinctWithQuery with headers**

```php
$distinctQuery = $g->sys->db->distinctQuery(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    headers: [
        'x-am-response-case' => 'capitalCase', // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    ],
);
```

**C#**

**distinctWithQuery with headers**

```csharp
var distinctQuery = await g.Sys.Db.DistinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
{
    Headers = new JsonObject
    {
        ["x-am-response-case"] = "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    },
});
```

**Go**

**distinctWithQuery with headers**

```go
distinctQuery, err := g.Sys.Db.DistinctQuery(am.Distinct{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	DistinctField: "first_name",
	Headers: am.M{
		"x-am-response-case": "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**distinctWithQuery with headers**

```rust
let distinct_query = g.sys.db.distinct_query(
    Distinct::new("mysql_8", "inventory", "customers", "first_name")
        .headers(json!({
            "x-am-response-case": "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        })),
)?;
```

**Java**

**distinctWithQuery with headers**

```java
var distinctQuery = g.sys.db.distinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
    .headers(Map.of(
        "x-am-response-case", "capitalCase" // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    )));
```

**Kotlin**

**distinctWithQuery with headers**

```kotlin
val distinctQuery = g.sys.db.distinctQuery(
    Distinct("mysql_8", "inventory", "customers", "first_name")
        .headers(mapOf(
            "x-am-response-case" to "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        )),
)
```

## distinctWithQuery with order
### ascending

**TypeScript**

**distinctWithQuery with ascending order**

```typescript
let distinctQuery = await g.sys.db.distinctQuery({
    instance: "mysql_8", database: "inventory", collection: "customers",
    distinctField: "first_name",
    order: "asc"
});
```

**Python**

**distinctWithQuery with ascending order**

```python
distinct_query = await g.sys.db.distinct_query(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    order='asc',
)
```

**PHP**

**distinctWithQuery with ascending order**

```php
$distinctQuery = $g->sys->db->distinctQuery(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    order: 'asc',
);
```

**C#**

**distinctWithQuery with ascending order**

```csharp
var distinctQuery = await g.Sys.Db.DistinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
{
    Order = "asc",
});
```

**Go**

**distinctWithQuery with ascending order**

```go
distinctQuery, err := g.Sys.Db.DistinctQuery(am.Distinct{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	DistinctField: "first_name",
	Order:         "asc",
})
if err != nil {
	return nil, err
}
```

**Rust**

**distinctWithQuery with ascending order**

```rust
let distinct_query = g.sys.db.distinct_query(
    Distinct::new("mysql_8", "inventory", "customers", "first_name")
        .order("asc"),
)?;
```

**Java**

**distinctWithQuery with ascending order**

```java
var distinctQuery = g.sys.db.distinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
    .order("asc"));
```

**Kotlin**

**distinctWithQuery with ascending order**

```kotlin
val distinctQuery = g.sys.db.distinctQuery(
    Distinct("mysql_8", "inventory", "customers", "first_name")
        .order("asc"),
)
```

### descending

**TypeScript**

**distinctWithQuery with descending order**

```typescript
let distinctQuery = await g.sys.db.distinctQuery({
    instance: "mysql_8", database: "inventory", collection: "customers",
    distinctField: "first_name",
    order: "desc"
});
```

**Python**

**distinctWithQuery with descending order**

```python
distinct_query = await g.sys.db.distinct_query(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    order='desc',
)
```

**PHP**

**distinctWithQuery with descending order**

```php
$distinctQuery = $g->sys->db->distinctQuery(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    order: 'desc',
);
```

**C#**

**distinctWithQuery with descending order**

```csharp
var distinctQuery = await g.Sys.Db.DistinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
{
    Order = "desc",
});
```

**Go**

**distinctWithQuery with descending order**

```go
distinctQuery, err := g.Sys.Db.DistinctQuery(am.Distinct{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	DistinctField: "first_name",
	Order:         "desc",
})
if err != nil {
	return nil, err
}
```

**Rust**

**distinctWithQuery with descending order**

```rust
let distinct_query = g.sys.db.distinct_query(
    Distinct::new("mysql_8", "inventory", "customers", "first_name")
        .order("desc"),
)?;
```

**Java**

**distinctWithQuery with descending order**

```java
var distinctQuery = g.sys.db.distinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
    .order("desc"));
```

**Kotlin**

**distinctWithQuery with descending order**

```kotlin
val distinctQuery = g.sys.db.distinctQuery(
    Distinct("mysql_8", "inventory", "customers", "first_name")
        .order("desc"),
)
```

## distinctWithQuery with find

**TypeScript**

**distinctWithQuery with find**

```typescript
let distinctQuery = await g.sys.db.distinctQuery({
    instance: "mysql_8", database: "inventory", collection: "customers",
    distinctField: "first_name",
    find: {
        first_name: "Bob"
    }
});
```

**Python**

**distinctWithQuery with find**

```python
distinct_query = await g.sys.db.distinct_query(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    find={
        'first_name': 'Bob',
    },
)
```

**PHP**

**distinctWithQuery with find**

```php
$distinctQuery = $g->sys->db->distinctQuery(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    find: [
        'first_name' => 'Bob',
    ],
);
```

**C#**

**distinctWithQuery with find**

```csharp
var distinctQuery = await g.Sys.Db.DistinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
{
    Find = new JsonObject
    {
        ["first_name"] = "Bob",
    },
});
```

**Go**

**distinctWithQuery with find**

```go
distinctQuery, err := g.Sys.Db.DistinctQuery(am.Distinct{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	DistinctField: "first_name",
	Find: am.M{
		"first_name": "Bob",
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**distinctWithQuery with find**

```rust
let distinct_query = g.sys.db.distinct_query(
    Distinct::new("mysql_8", "inventory", "customers", "first_name")
        .find(json!({
            "first_name": "Bob",
        })),
)?;
```

**Java**

**distinctWithQuery with find**

```java
var distinctQuery = g.sys.db.distinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
    .find(Map.of(
        "first_name", "Bob"
    )));
```

**Kotlin**

**distinctWithQuery with find**

```kotlin
val distinctQuery = g.sys.db.distinctQuery(
    Distinct("mysql_8", "inventory", "customers", "first_name")
        .find(mapOf(
            "first_name" to "Bob",
        )),
)
```

## $lt distinctWithQuery

**TypeScript**

**distinctWithQuery with $lt**

```typescript
let distinctQuery = await g.sys.db.distinctQuery({
    instance: "mysql_8", database: "inventory", collection: "customers",
    distinctField: "first_name",
    find: {
        customer_id: {
            "$lt": 2
        }
    }
});
```

**Python**

**distinctWithQuery with $lt**

```python
distinct_query = await g.sys.db.distinct_query(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    find={
        'customer_id': {
            '$lt': 2,
        },
    },
)
```

**PHP**

**distinctWithQuery with $lt**

```php
$distinctQuery = $g->sys->db->distinctQuery(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    find: [
        'customer_id' => [
            '$lt' => 2,
        ],
    ],
);
```

**C#**

**distinctWithQuery with $lt**

```csharp
var distinctQuery = await g.Sys.Db.DistinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
{
    Find = new JsonObject
    {
        ["customer_id"] = new JsonObject
        {
            ["$lt"] = 2,
        },
    },
});
```

**Go**

**distinctWithQuery with $lt**

```go
distinctQuery, err := g.Sys.Db.DistinctQuery(am.Distinct{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	DistinctField: "first_name",
	Find: am.M{
		"customer_id": am.M{
			"$lt": 2,
		},
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**distinctWithQuery with $lt**

```rust
let distinct_query = g.sys.db.distinct_query(
    Distinct::new("mysql_8", "inventory", "customers", "first_name")
        .find(json!({
            "customer_id": {
                "$lt": 2,
            },
        })),
)?;
```

**Java**

**distinctWithQuery with $lt**

```java
var distinctQuery = g.sys.db.distinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
    .find(Map.of(
        "customer_id", Map.of(
            "$lt", 2
        )
    )));
```

**Kotlin**

**distinctWithQuery with $lt**

```kotlin
val distinctQuery = g.sys.db.distinctQuery(
    Distinct("mysql_8", "inventory", "customers", "first_name")
        .find(mapOf(
            "customer_id" to mapOf(
                "\$lt" to 2,
            ),
        )),
)
```

## $lte distinctWithQuery

**TypeScript**

**distinctWithQuery with $lte**

```typescript
let distinctQuery = await g.sys.db.distinctQuery({
    instance: "mysql_8", database: "inventory", collection: "customers",
    distinctField: "first_name",
    find: {
        customer_id: {
            "$lte": 2
        }
    }
});
```

**Python**

**distinctWithQuery with $lte**

```python
distinct_query = await g.sys.db.distinct_query(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    find={
        'customer_id': {
            '$lte': 2,
        },
    },
)
```

**PHP**

**distinctWithQuery with $lte**

```php
$distinctQuery = $g->sys->db->distinctQuery(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    find: [
        'customer_id' => [
            '$lte' => 2,
        ],
    ],
);
```

**C#**

**distinctWithQuery with $lte**

```csharp
var distinctQuery = await g.Sys.Db.DistinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
{
    Find = new JsonObject
    {
        ["customer_id"] = new JsonObject
        {
            ["$lte"] = 2,
        },
    },
});
```

**Go**

**distinctWithQuery with $lte**

```go
distinctQuery, err := g.Sys.Db.DistinctQuery(am.Distinct{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	DistinctField: "first_name",
	Find: am.M{
		"customer_id": am.M{
			"$lte": 2,
		},
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**distinctWithQuery with $lte**

```rust
let distinct_query = g.sys.db.distinct_query(
    Distinct::new("mysql_8", "inventory", "customers", "first_name")
        .find(json!({
            "customer_id": {
                "$lte": 2,
            },
        })),
)?;
```

**Java**

**distinctWithQuery with $lte**

```java
var distinctQuery = g.sys.db.distinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
    .find(Map.of(
        "customer_id", Map.of(
            "$lte", 2
        )
    )));
```

**Kotlin**

**distinctWithQuery with $lte**

```kotlin
val distinctQuery = g.sys.db.distinctQuery(
    Distinct("mysql_8", "inventory", "customers", "first_name")
        .find(mapOf(
            "customer_id" to mapOf(
                "\$lte" to 2,
            ),
        )),
)
```

## $gt distinctWithQuery

**TypeScript**

**distinctWithQuery with $gt**

```typescript
let distinctQuery = await g.sys.db.distinctQuery({
    instance: "mysql_8", database: "inventory", collection: "customers",
    distinctField: "first_name",
    find: {
        customer_id: {
            "$gt": 2
        }
    }
});
```

**Python**

**distinctWithQuery with $gt**

```python
distinct_query = await g.sys.db.distinct_query(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    find={
        'customer_id': {
            '$gt': 2,
        },
    },
)
```

**PHP**

**distinctWithQuery with $gt**

```php
$distinctQuery = $g->sys->db->distinctQuery(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    find: [
        'customer_id' => [
            '$gt' => 2,
        ],
    ],
);
```

**C#**

**distinctWithQuery with $gt**

```csharp
var distinctQuery = await g.Sys.Db.DistinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
{
    Find = new JsonObject
    {
        ["customer_id"] = new JsonObject
        {
            ["$gt"] = 2,
        },
    },
});
```

**Go**

**distinctWithQuery with $gt**

```go
distinctQuery, err := g.Sys.Db.DistinctQuery(am.Distinct{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	DistinctField: "first_name",
	Find: am.M{
		"customer_id": am.M{
			"$gt": 2,
		},
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**distinctWithQuery with $gt**

```rust
let distinct_query = g.sys.db.distinct_query(
    Distinct::new("mysql_8", "inventory", "customers", "first_name")
        .find(json!({
            "customer_id": {
                "$gt": 2,
            },
        })),
)?;
```

**Java**

**distinctWithQuery with $gt**

```java
var distinctQuery = g.sys.db.distinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
    .find(Map.of(
        "customer_id", Map.of(
            "$gt", 2
        )
    )));
```

**Kotlin**

**distinctWithQuery with $gt**

```kotlin
val distinctQuery = g.sys.db.distinctQuery(
    Distinct("mysql_8", "inventory", "customers", "first_name")
        .find(mapOf(
            "customer_id" to mapOf(
                "\$gt" to 2,
            ),
        )),
)
```

## $gte distinctWithQuery

**TypeScript**

**distinctWithQuery with $gte**

```typescript
let distinctQuery = await g.sys.db.distinctQuery({
    instance: "mysql_8", database: "inventory", collection: "customers",
    distinctField: "first_name",
    find: {
        customer_id: {
            "$gte": 2
        }
    }
});
```

**Python**

**distinctWithQuery with $gte**

```python
distinct_query = await g.sys.db.distinct_query(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    find={
        'customer_id': {
            '$gte': 2,
        },
    },
)
```

**PHP**

**distinctWithQuery with $gte**

```php
$distinctQuery = $g->sys->db->distinctQuery(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    find: [
        'customer_id' => [
            '$gte' => 2,
        ],
    ],
);
```

**C#**

**distinctWithQuery with $gte**

```csharp
var distinctQuery = await g.Sys.Db.DistinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
{
    Find = new JsonObject
    {
        ["customer_id"] = new JsonObject
        {
            ["$gte"] = 2,
        },
    },
});
```

**Go**

**distinctWithQuery with $gte**

```go
distinctQuery, err := g.Sys.Db.DistinctQuery(am.Distinct{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	DistinctField: "first_name",
	Find: am.M{
		"customer_id": am.M{
			"$gte": 2,
		},
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**distinctWithQuery with $gte**

```rust
let distinct_query = g.sys.db.distinct_query(
    Distinct::new("mysql_8", "inventory", "customers", "first_name")
        .find(json!({
            "customer_id": {
                "$gte": 2,
            },
        })),
)?;
```

**Java**

**distinctWithQuery with $gte**

```java
var distinctQuery = g.sys.db.distinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
    .find(Map.of(
        "customer_id", Map.of(
            "$gte", 2
        )
    )));
```

**Kotlin**

**distinctWithQuery with $gte**

```kotlin
val distinctQuery = g.sys.db.distinctQuery(
    Distinct("mysql_8", "inventory", "customers", "first_name")
        .find(mapOf(
            "customer_id" to mapOf(
                "\$gte" to 2,
            ),
        )),
)
```

## $eq distinctWithQuery

**TypeScript**

**distinctWithQuery with $eq**

```typescript
let distinctQuery = await g.sys.db.distinctQuery({
    instance: "mysql_8", database: "inventory", collection: "customers",
    distinctField: "first_name",
    find: {
        customer_id: {
            "$eq": 2
        }
    }
});
```

**Python**

**distinctWithQuery with $eq**

```python
distinct_query = await g.sys.db.distinct_query(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    find={
        'customer_id': {
            '$eq': 2,
        },
    },
)
```

**PHP**

**distinctWithQuery with $eq**

```php
$distinctQuery = $g->sys->db->distinctQuery(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    find: [
        'customer_id' => [
            '$eq' => 2,
        ],
    ],
);
```

**C#**

**distinctWithQuery with $eq**

```csharp
var distinctQuery = await g.Sys.Db.DistinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
{
    Find = new JsonObject
    {
        ["customer_id"] = new JsonObject
        {
            ["$eq"] = 2,
        },
    },
});
```

**Go**

**distinctWithQuery with $eq**

```go
distinctQuery, err := g.Sys.Db.DistinctQuery(am.Distinct{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	DistinctField: "first_name",
	Find: am.M{
		"customer_id": am.M{
			"$eq": 2,
		},
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**distinctWithQuery with $eq**

```rust
let distinct_query = g.sys.db.distinct_query(
    Distinct::new("mysql_8", "inventory", "customers", "first_name")
        .find(json!({
            "customer_id": {
                "$eq": 2,
            },
        })),
)?;
```

**Java**

**distinctWithQuery with $eq**

```java
var distinctQuery = g.sys.db.distinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
    .find(Map.of(
        "customer_id", Map.of(
            "$eq", 2
        )
    )));
```

**Kotlin**

**distinctWithQuery with $eq**

```kotlin
val distinctQuery = g.sys.db.distinctQuery(
    Distinct("mysql_8", "inventory", "customers", "first_name")
        .find(mapOf(
            "customer_id" to mapOf(
                "\$eq" to 2,
            ),
        )),
)
```

## $ne distinctWithQuery

**TypeScript**

**distinctWithQuery with $ne**

```typescript
let distinctQuery = await g.sys.db.distinctQuery({
    instance: "mysql_8", database: "inventory", collection: "customers",
    distinctField: "first_name",
    find: {
        customer_id: {
            "$ne": 2
        }
    }
});
```

**Python**

**distinctWithQuery with $ne**

```python
distinct_query = await g.sys.db.distinct_query(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    find={
        'customer_id': {
            '$ne': 2,
        },
    },
)
```

**PHP**

**distinctWithQuery with $ne**

```php
$distinctQuery = $g->sys->db->distinctQuery(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    find: [
        'customer_id' => [
            '$ne' => 2,
        ],
    ],
);
```

**C#**

**distinctWithQuery with $ne**

```csharp
var distinctQuery = await g.Sys.Db.DistinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
{
    Find = new JsonObject
    {
        ["customer_id"] = new JsonObject
        {
            ["$ne"] = 2,
        },
    },
});
```

**Go**

**distinctWithQuery with $ne**

```go
distinctQuery, err := g.Sys.Db.DistinctQuery(am.Distinct{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	DistinctField: "first_name",
	Find: am.M{
		"customer_id": am.M{
			"$ne": 2,
		},
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**distinctWithQuery with $ne**

```rust
let distinct_query = g.sys.db.distinct_query(
    Distinct::new("mysql_8", "inventory", "customers", "first_name")
        .find(json!({
            "customer_id": {
                "$ne": 2,
            },
        })),
)?;
```

**Java**

**distinctWithQuery with $ne**

```java
var distinctQuery = g.sys.db.distinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
    .find(Map.of(
        "customer_id", Map.of(
            "$ne", 2
        )
    )));
```

**Kotlin**

**distinctWithQuery with $ne**

```kotlin
val distinctQuery = g.sys.db.distinctQuery(
    Distinct("mysql_8", "inventory", "customers", "first_name")
        .find(mapOf(
            "customer_id" to mapOf(
                "\$ne" to 2,
            ),
        )),
)
```

## $not distinctWithQuery

**TypeScript**

**distinctWithQuery with $not**

```typescript
let distinctQuery = await g.sys.db.distinctQuery({
    instance: "mysql_8", database: "inventory", collection: "customers",
    distinctField: "first_name",
    find: {
        customer_id: {
            "$not": {
                "$in": [1,2,3]
            }
        }
    }
});
```

**Python**

**distinctWithQuery with $not**

```python
distinct_query = await g.sys.db.distinct_query(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    find={
        'customer_id': {
            '$not': {
                '$in': [1, 2, 3],
            },
        },
    },
)
```

**PHP**

**distinctWithQuery with $not**

```php
$distinctQuery = $g->sys->db->distinctQuery(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    find: [
        'customer_id' => [
            '$not' => [
                '$in' => [1, 2, 3],
            ],
        ],
    ],
);
```

**C#**

**distinctWithQuery with $not**

```csharp
var distinctQuery = await g.Sys.Db.DistinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
{
    Find = new JsonObject
    {
        ["customer_id"] = new JsonObject
        {
            ["$not"] = new JsonObject
            {
                ["$in"] = new JsonArray { 1, 2, 3 },
            },
        },
    },
});
```

**Go**

**distinctWithQuery with $not**

```go
distinctQuery, err := g.Sys.Db.DistinctQuery(am.Distinct{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	DistinctField: "first_name",
	Find: am.M{
		"customer_id": am.M{
			"$not": am.M{
				"$in": []any{1, 2, 3},
			},
		},
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**distinctWithQuery with $not**

```rust
let distinct_query = g.sys.db.distinct_query(
    Distinct::new("mysql_8", "inventory", "customers", "first_name")
        .find(json!({
            "customer_id": {
                "$not": {
                    "$in": [1, 2, 3],
                },
            },
        })),
)?;
```

**Java**

**distinctWithQuery with $not**

```java
var distinctQuery = g.sys.db.distinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
    .find(Map.of(
        "customer_id", Map.of(
            "$not", Map.of(
                "$in", List.of(1, 2, 3)
            )
        )
    )));
```

**Kotlin**

**distinctWithQuery with $not**

```kotlin
val distinctQuery = g.sys.db.distinctQuery(
    Distinct("mysql_8", "inventory", "customers", "first_name")
        .find(mapOf(
            "customer_id" to mapOf(
                "\$not" to mapOf(
                    "\$in" to listOf(1, 2, 3),
                ),
            ),
        )),
)
```

## $and distinctWithQuery

**TypeScript**

**distinctWithQuery with $and**

```typescript
let distinctQuery = await g.sys.db.distinctQuery({
    instance: "mysql_8", database: "inventory", collection: "customers",
    distinctField: "first_name",
    find: {
        "$and": [
            {
                "customer_id": 1
            },
            {
                "zipcode": 382345
            }
        ]
    }
});
```

**Python**

**distinctWithQuery with $and**

```python
distinct_query = await g.sys.db.distinct_query(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    find={
        '$and': [
            {
                'customer_id': 1,
            },
            {
                'zipcode': 382345,
            },
        ],
    },
)
```

**PHP**

**distinctWithQuery with $and**

```php
$distinctQuery = $g->sys->db->distinctQuery(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    find: [
        '$and' => [
            [
                'customer_id' => 1,
            ],
            [
                'zipcode' => 382345,
            ],
        ],
    ],
);
```

**C#**

**distinctWithQuery with $and**

```csharp
var distinctQuery = await g.Sys.Db.DistinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
{
    Find = new JsonObject
    {
        ["$and"] = new JsonArray
        {
            new JsonObject
            {
                ["customer_id"] = 1,
            },
            new JsonObject
            {
                ["zipcode"] = 382345,
            },
        },
    },
});
```

**Go**

**distinctWithQuery with $and**

```go
distinctQuery, err := g.Sys.Db.DistinctQuery(am.Distinct{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	DistinctField: "first_name",
	Find: am.M{
		"$and": []any{
			am.M{
				"customer_id": 1,
			},
			am.M{
				"zipcode": 382345,
			},
		},
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**distinctWithQuery with $and**

```rust
let distinct_query = g.sys.db.distinct_query(
    Distinct::new("mysql_8", "inventory", "customers", "first_name")
        .find(json!({
            "$and": [
                {
                    "customer_id": 1,
                },
                {
                    "zipcode": 382345,
                },
            ],
        })),
)?;
```

**Java**

**distinctWithQuery with $and**

```java
var distinctQuery = g.sys.db.distinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
    .find(Map.of(
        "$and", List.of(
            Map.of(
                "customer_id", 1
            ),
            Map.of(
                "zipcode", 382345
            )
        )
    )));
```

**Kotlin**

**distinctWithQuery with $and**

```kotlin
val distinctQuery = g.sys.db.distinctQuery(
    Distinct("mysql_8", "inventory", "customers", "first_name")
        .find(mapOf(
            "\$and" to listOf(
                mapOf(
                    "customer_id" to 1,
                ),
                mapOf(
                    "zipcode" to 382345,
                ),
            ),
        )),
)
```

## $or distinctWithQuery

**TypeScript**

**distinctWithQuery with $or**

```typescript
let distinctQuery = await g.sys.db.distinctQuery({
    instance: "mysql_8", database: "inventory", collection: "customers",
    distinctField: "first_name",
    find: {
        "$or": [
            {
                "customer_id": 1
            },
            {
                "zipcode": 382345
            }
        ]
    }
});
```

**Python**

**distinctWithQuery with $or**

```python
distinct_query = await g.sys.db.distinct_query(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    find={
        '$or': [
            {
                'customer_id': 1,
            },
            {
                'zipcode': 382345,
            },
        ],
    },
)
```

**PHP**

**distinctWithQuery with $or**

```php
$distinctQuery = $g->sys->db->distinctQuery(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    find: [
        '$or' => [
            [
                'customer_id' => 1,
            ],
            [
                'zipcode' => 382345,
            ],
        ],
    ],
);
```

**C#**

**distinctWithQuery with $or**

```csharp
var distinctQuery = await g.Sys.Db.DistinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
{
    Find = new JsonObject
    {
        ["$or"] = new JsonArray
        {
            new JsonObject
            {
                ["customer_id"] = 1,
            },
            new JsonObject
            {
                ["zipcode"] = 382345,
            },
        },
    },
});
```

**Go**

**distinctWithQuery with $or**

```go
distinctQuery, err := g.Sys.Db.DistinctQuery(am.Distinct{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	DistinctField: "first_name",
	Find: am.M{
		"$or": []any{
			am.M{
				"customer_id": 1,
			},
			am.M{
				"zipcode": 382345,
			},
		},
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**distinctWithQuery with $or**

```rust
let distinct_query = g.sys.db.distinct_query(
    Distinct::new("mysql_8", "inventory", "customers", "first_name")
        .find(json!({
            "$or": [
                {
                    "customer_id": 1,
                },
                {
                    "zipcode": 382345,
                },
            ],
        })),
)?;
```

**Java**

**distinctWithQuery with $or**

```java
var distinctQuery = g.sys.db.distinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
    .find(Map.of(
        "$or", List.of(
            Map.of(
                "customer_id", 1
            ),
            Map.of(
                "zipcode", 382345
            )
        )
    )));
```

**Kotlin**

**distinctWithQuery with $or**

```kotlin
val distinctQuery = g.sys.db.distinctQuery(
    Distinct("mysql_8", "inventory", "customers", "first_name")
        .find(mapOf(
            "\$or" to listOf(
                mapOf(
                    "customer_id" to 1,
                ),
                mapOf(
                    "zipcode" to 382345,
                ),
            ),
        )),
)
```

## $in distinctWithQuery

**TypeScript**

**distinctWithQuery with $in**

```typescript
let distinctQuery = await g.sys.db.distinctQuery({
    instance: "mysql_8", database: "inventory", collection: "customers",
    distinctField: "first_name",
    find: {
        customer_id: {
            "$in": [1, 2,3]
        }
    }
});
```

**Python**

**distinctWithQuery with $in**

```python
distinct_query = await g.sys.db.distinct_query(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    find={
        'customer_id': {
            '$in': [1, 2, 3],
        },
    },
)
```

**PHP**

**distinctWithQuery with $in**

```php
$distinctQuery = $g->sys->db->distinctQuery(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    find: [
        'customer_id' => [
            '$in' => [1, 2, 3],
        ],
    ],
);
```

**C#**

**distinctWithQuery with $in**

```csharp
var distinctQuery = await g.Sys.Db.DistinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
{
    Find = new JsonObject
    {
        ["customer_id"] = new JsonObject
        {
            ["$in"] = new JsonArray { 1, 2, 3 },
        },
    },
});
```

**Go**

**distinctWithQuery with $in**

```go
distinctQuery, err := g.Sys.Db.DistinctQuery(am.Distinct{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	DistinctField: "first_name",
	Find: am.M{
		"customer_id": am.M{
			"$in": []any{1, 2, 3},
		},
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**distinctWithQuery with $in**

```rust
let distinct_query = g.sys.db.distinct_query(
    Distinct::new("mysql_8", "inventory", "customers", "first_name")
        .find(json!({
            "customer_id": {
                "$in": [1, 2, 3],
            },
        })),
)?;
```

**Java**

**distinctWithQuery with $in**

```java
var distinctQuery = g.sys.db.distinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
    .find(Map.of(
        "customer_id", Map.of(
            "$in", List.of(1, 2, 3)
        )
    )));
```

**Kotlin**

**distinctWithQuery with $in**

```kotlin
val distinctQuery = g.sys.db.distinctQuery(
    Distinct("mysql_8", "inventory", "customers", "first_name")
        .find(mapOf(
            "customer_id" to mapOf(
                "\$in" to listOf(1, 2, 3),
            ),
        )),
)
```

## $nin distinctWithQuery

**TypeScript**

**distinctWithQuery with $nin**

```typescript
let distinctQuery = await g.sys.db.distinctQuery({
    instance: "mysql_8", database: "inventory", collection: "customers",
    distinctField: "first_name",
    find: {
        customer_id: {
            "$nin": [1, 2,3]
        }
    }
});
```

**Python**

**distinctWithQuery with $nin**

```python
distinct_query = await g.sys.db.distinct_query(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    find={
        'customer_id': {
            '$nin': [1, 2, 3],
        },
    },
)
```

**PHP**

**distinctWithQuery with $nin**

```php
$distinctQuery = $g->sys->db->distinctQuery(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    find: [
        'customer_id' => [
            '$nin' => [1, 2, 3],
        ],
    ],
);
```

**C#**

**distinctWithQuery with $nin**

```csharp
var distinctQuery = await g.Sys.Db.DistinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
{
    Find = new JsonObject
    {
        ["customer_id"] = new JsonObject
        {
            ["$nin"] = new JsonArray { 1, 2, 3 },
        },
    },
});
```

**Go**

**distinctWithQuery with $nin**

```go
distinctQuery, err := g.Sys.Db.DistinctQuery(am.Distinct{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	DistinctField: "first_name",
	Find: am.M{
		"customer_id": am.M{
			"$nin": []any{1, 2, 3},
		},
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**distinctWithQuery with $nin**

```rust
let distinct_query = g.sys.db.distinct_query(
    Distinct::new("mysql_8", "inventory", "customers", "first_name")
        .find(json!({
            "customer_id": {
                "$nin": [1, 2, 3],
            },
        })),
)?;
```

**Java**

**distinctWithQuery with $nin**

```java
var distinctQuery = g.sys.db.distinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
    .find(Map.of(
        "customer_id", Map.of(
            "$nin", List.of(1, 2, 3)
        )
    )));
```

**Kotlin**

**distinctWithQuery with $nin**

```kotlin
val distinctQuery = g.sys.db.distinctQuery(
    Distinct("mysql_8", "inventory", "customers", "first_name")
        .find(mapOf(
            "customer_id" to mapOf(
                "\$nin" to listOf(1, 2, 3),
            ),
        )),
)
```

## $like distinctWithQuery

**TypeScript**

**distinctWithQuery with $like**

```typescript
let distinctQuery = await g.sys.db.distinctQuery({
    instance: "mysql_8", database: "inventory", collection: "customers",
    distinctField: "first_name",
    find: {
        first_name: {
            "$like": "Bob%"
        }
    }
});
```

**Python**

**distinctWithQuery with $like**

```python
distinct_query = await g.sys.db.distinct_query(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    find={
        'first_name': {
            '$like': 'Bob%',
        },
    },
)
```

**PHP**

**distinctWithQuery with $like**

```php
$distinctQuery = $g->sys->db->distinctQuery(
    'mysql_8', 'inventory', 'customers',
    'first_name',
    find: [
        'first_name' => [
            '$like' => 'Bob%',
        ],
    ],
);
```

**C#**

**distinctWithQuery with $like**

```csharp
var distinctQuery = await g.Sys.Db.DistinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
{
    Find = new JsonObject
    {
        ["first_name"] = new JsonObject
        {
            ["$like"] = "Bob%",
        },
    },
});
```

**Go**

**distinctWithQuery with $like**

```go
distinctQuery, err := g.Sys.Db.DistinctQuery(am.Distinct{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	DistinctField: "first_name",
	Find: am.M{
		"first_name": am.M{
			"$like": "Bob%",
		},
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**distinctWithQuery with $like**

```rust
let distinct_query = g.sys.db.distinct_query(
    Distinct::new("mysql_8", "inventory", "customers", "first_name")
        .find(json!({
            "first_name": {
                "$like": "Bob%",
            },
        })),
)?;
```

**Java**

**distinctWithQuery with $like**

```java
var distinctQuery = g.sys.db.distinctQuery(new Distinct("mysql_8", "inventory", "customers", "first_name")
    .find(Map.of(
        "first_name", Map.of(
            "$like", "Bob%"
        )
    )));
```

**Kotlin**

**distinctWithQuery with $like**

```kotlin
val distinctQuery = g.sys.db.distinctQuery(
    Distinct("mysql_8", "inventory", "customers", "first_name")
        .find(mapOf(
            "first_name" to mapOf(
                "\$like" to "Bob%",
            ),
        )),
)
```

## Structure

**TypeScript**

**Distinct Query**

```typescript
let distinctQuery = await g.sys.db.distinctQuery({
    instance: "INSTANCE_NAME", database: 'DB_NAME', collection: "COLLECTION_NAME",
    distinctField: "COLUMN_NAME",
    order: "asc", // asc | desc
    find: {
        "COLUMN_NAME": "VALUE",
    },
    headers: {
        "x-am-response-case": "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        "x-am-response-object-type": "make_flat", // no_action | make_flat
        "x-am-meta": "true", // true, false
        "x-am-internationalization": "USER_I18N_ID",
        "x-am-run-in-sandbox": "2",
        "x-am-content-type-response": "text/xml", // application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
        "x-am-cache-control": "reset_cache", // no_action | reset_cache
        "x-am-get-encrypted-data": "get_only_encryption", // no_encryption | get_only_encryption | get_data_and_encryption
        "x-am-sandbox-timeout": "13000",
        "x-no-compression": "true", // true | false
        "x-am-encrypted-payload": "true", // user will send 'true', when payload is encrypted for transfer
        // Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
        "x-am-tenant-username": "TENANT_USERNAME", // ex: acme
        // Authorization headers
        "x-am-authorization": "AUTHORIZATION_TOKEN",
        "x-am-user-authorization": "API_USER_TOKEN",
        "x-aws-authorization": "AWS_TOKEN",
        "x-google-authorization": "GOOGLE_TOKEN",
        "x-azure-authorization": "AZURE_TOKEN",
    },
});
```

**Python**

**Distinct Query**

```python
distinct_query = await g.sys.db.distinct_query(
    'INSTANCE_NAME', 'DB_NAME', 'COLLECTION_NAME',
    'COLUMN_NAME',
    order='asc',  # asc | desc
    find={
        'COLUMN_NAME': 'VALUE',
    },
    headers={
        'x-am-response-case': 'capitalCase',  # noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        'x-am-response-object-type': 'make_flat',  # no_action | make_flat
        'x-am-meta': 'true',  # true, false
        'x-am-internationalization': 'USER_I18N_ID',
        'x-am-run-in-sandbox': '2',
        'x-am-content-type-response': 'text/xml',  # application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
        'x-am-cache-control': 'reset_cache',  # no_action | reset_cache
        'x-am-get-encrypted-data': 'get_only_encryption',  # no_encryption | get_only_encryption | get_data_and_encryption
        'x-am-sandbox-timeout': '13000',
        'x-no-compression': 'true',  # true | false
        'x-am-encrypted-payload': 'true',  # user will send 'true', when payload is encrypted for transfer
        # Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
        'x-am-tenant-username': 'TENANT_USERNAME',  # ex: acme
        # Authorization headers
        'x-am-authorization': 'AUTHORIZATION_TOKEN',
        'x-am-user-authorization': 'API_USER_TOKEN',
        'x-aws-authorization': 'AWS_TOKEN',
        'x-google-authorization': 'GOOGLE_TOKEN',
        'x-azure-authorization': 'AZURE_TOKEN',
    },
)
```

**PHP**

**Distinct Query**

```php
$distinctQuery = $g->sys->db->distinctQuery(
    'INSTANCE_NAME', 'DB_NAME', 'COLLECTION_NAME',
    'COLUMN_NAME',
    order: 'asc', // asc | desc
    find: [
        'COLUMN_NAME' => 'VALUE',
    ],
    headers: [
        'x-am-response-case' => 'capitalCase', // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        'x-am-response-object-type' => 'make_flat', // no_action | make_flat
        'x-am-meta' => 'true', // true, false
        'x-am-internationalization' => 'USER_I18N_ID',
        'x-am-run-in-sandbox' => '2',
        'x-am-content-type-response' => 'text/xml', // application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
        'x-am-cache-control' => 'reset_cache', // no_action | reset_cache
        'x-am-get-encrypted-data' => 'get_only_encryption', // no_encryption | get_only_encryption | get_data_and_encryption
        'x-am-sandbox-timeout' => '13000',
        'x-no-compression' => 'true', // true | false
        'x-am-encrypted-payload' => 'true', // user will send 'true', when payload is encrypted for transfer
        // Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
        'x-am-tenant-username' => 'TENANT_USERNAME', // ex: acme
        // Authorization headers
        'x-am-authorization' => 'AUTHORIZATION_TOKEN',
        'x-am-user-authorization' => 'API_USER_TOKEN',
        'x-aws-authorization' => 'AWS_TOKEN',
        'x-google-authorization' => 'GOOGLE_TOKEN',
        'x-azure-authorization' => 'AZURE_TOKEN',
    ],
);
```

**C#**

**Distinct Query**

```csharp
var distinctQuery = await g.Sys.Db.DistinctQuery(new Distinct("INSTANCE_NAME", "DB_NAME", "COLLECTION_NAME", "COLUMN_NAME")
{
    Order = "asc", // asc | desc
    Find = new JsonObject
    {
        ["COLUMN_NAME"] = "VALUE",
    },
    Headers = new JsonObject
    {
        ["x-am-response-case"] = "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        ["x-am-response-object-type"] = "make_flat", // no_action | make_flat
        ["x-am-meta"] = "true", // true, false
        ["x-am-internationalization"] = "USER_I18N_ID",
        ["x-am-run-in-sandbox"] = "2",
        ["x-am-content-type-response"] = "text/xml", // application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
        ["x-am-cache-control"] = "reset_cache", // no_action | reset_cache
        ["x-am-get-encrypted-data"] = "get_only_encryption", // no_encryption | get_only_encryption | get_data_and_encryption
        ["x-am-sandbox-timeout"] = "13000",
        ["x-no-compression"] = "true", // true | false
        ["x-am-encrypted-payload"] = "true", // user will send 'true', when payload is encrypted for transfer
        // Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
        ["x-am-tenant-username"] = "TENANT_USERNAME", // ex: acme
        // Authorization headers
        ["x-am-authorization"] = "AUTHORIZATION_TOKEN",
        ["x-am-user-authorization"] = "API_USER_TOKEN",
        ["x-aws-authorization"] = "AWS_TOKEN",
        ["x-google-authorization"] = "GOOGLE_TOKEN",
        ["x-azure-authorization"] = "AZURE_TOKEN",
    },
});
```

**Go**

**Distinct Query**

```go
distinctQuery, err := g.Sys.Db.DistinctQuery(am.Distinct{
	Instance: "INSTANCE_NAME", Database: "DB_NAME", Collection: "COLLECTION_NAME",
	DistinctField: "COLUMN_NAME",
	Order:         "asc", // asc | desc
	Find: am.M{
		"COLUMN_NAME": "VALUE",
	},
	Headers: am.M{
		"x-am-response-case":         "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
		"x-am-response-object-type":  "make_flat",   // no_action | make_flat
		"x-am-meta":                  "true",        // true, false
		"x-am-internationalization":  "USER_I18N_ID",
		"x-am-run-in-sandbox":        "2",
		"x-am-content-type-response": "text/xml",            // application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
		"x-am-cache-control":         "reset_cache",         // no_action | reset_cache
		"x-am-get-encrypted-data":    "get_only_encryption", // no_encryption | get_only_encryption | get_data_and_encryption
		"x-am-sandbox-timeout":       "13000",
		"x-no-compression":           "true", // true | false
		"x-am-encrypted-payload":     "true", // user will send 'true', when payload is encrypted for transfer
		// Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
		"x-am-tenant-username": "TENANT_USERNAME", // ex: acme
		// Authorization headers
		"x-am-authorization":      "AUTHORIZATION_TOKEN",
		"x-am-user-authorization": "API_USER_TOKEN",
		"x-aws-authorization":     "AWS_TOKEN",
		"x-google-authorization":  "GOOGLE_TOKEN",
		"x-azure-authorization":   "AZURE_TOKEN",
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**Distinct Query**

```rust
let distinct_query = g.sys.db.distinct_query(
    Distinct::new("INSTANCE_NAME", "DB_NAME", "COLLECTION_NAME", "COLUMN_NAME")
        .order("asc") // asc | desc
        .find(json!({
            "COLUMN_NAME": "VALUE",
        }))
        .headers(json!({
            "x-am-response-case": "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
            "x-am-response-object-type": "make_flat", // no_action | make_flat
            "x-am-meta": "true", // true, false
            "x-am-internationalization": "USER_I18N_ID",
            "x-am-run-in-sandbox": "2",
            "x-am-content-type-response": "text/xml", // application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
            "x-am-cache-control": "reset_cache", // no_action | reset_cache
            "x-am-get-encrypted-data": "get_only_encryption", // no_encryption | get_only_encryption | get_data_and_encryption
            "x-am-sandbox-timeout": "13000",
            "x-no-compression": "true", // true | false
            "x-am-encrypted-payload": "true", // user will send 'true', when payload is encrypted for transfer
            // Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
            "x-am-tenant-username": "TENANT_USERNAME", // ex: acme
            // Authorization headers
            "x-am-authorization": "AUTHORIZATION_TOKEN",
            "x-am-user-authorization": "API_USER_TOKEN",
            "x-aws-authorization": "AWS_TOKEN",
            "x-google-authorization": "GOOGLE_TOKEN",
            "x-azure-authorization": "AZURE_TOKEN",
        })),
)?;
```

**Java**

**Distinct Query**

```java
var distinctQuery = g.sys.db.distinctQuery(new Distinct("INSTANCE_NAME", "DB_NAME", "COLLECTION_NAME", "COLUMN_NAME")
    .order("asc") // asc | desc
    .find(Map.of(
        "COLUMN_NAME", "VALUE"
    ))
    .headers(JsonObject.of(
        "x-am-response-case", "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        "x-am-response-object-type", "make_flat", // no_action | make_flat
        "x-am-meta", "true", // true, false
        "x-am-internationalization", "USER_I18N_ID",
        "x-am-run-in-sandbox", "2",
        "x-am-content-type-response", "text/xml", // application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
        "x-am-cache-control", "reset_cache", // no_action | reset_cache
        "x-am-get-encrypted-data", "get_only_encryption", // no_encryption | get_only_encryption | get_data_and_encryption
        "x-am-sandbox-timeout", "13000",
        "x-no-compression", "true", // true | false
        "x-am-encrypted-payload", "true", // user will send 'true', when payload is encrypted for transfer
        // Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
        "x-am-tenant-username", "TENANT_USERNAME", // ex: acme
        // Authorization headers
        "x-am-authorization", "AUTHORIZATION_TOKEN",
        "x-am-user-authorization", "API_USER_TOKEN",
        "x-aws-authorization", "AWS_TOKEN",
        "x-google-authorization", "GOOGLE_TOKEN",
        "x-azure-authorization", "AZURE_TOKEN"
    )));
```

**Kotlin**

**Distinct Query**

```kotlin
val distinctQuery = g.sys.db.distinctQuery(
    Distinct("INSTANCE_NAME", "DB_NAME", "COLLECTION_NAME", "COLUMN_NAME")
        .order("asc") // asc | desc
        .find(mapOf(
            "COLUMN_NAME" to "VALUE",
        ))
        .headers(mapOf(
            "x-am-response-case" to "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
            "x-am-response-object-type" to "make_flat", // no_action | make_flat
            "x-am-meta" to "true", // true, false
            "x-am-internationalization" to "USER_I18N_ID",
            "x-am-run-in-sandbox" to "2",
            "x-am-content-type-response" to "text/xml", // application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
            "x-am-cache-control" to "reset_cache", // no_action | reset_cache
            "x-am-get-encrypted-data" to "get_only_encryption", // no_encryption | get_only_encryption | get_data_and_encryption
            "x-am-sandbox-timeout" to "13000",
            "x-no-compression" to "true", // true | false
            "x-am-encrypted-payload" to "true", // user will send 'true', when payload is encrypted for transfer
            // Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
            "x-am-tenant-username" to "TENANT_USERNAME", // ex: acme
            // Authorization headers
            "x-am-authorization" to "AUTHORIZATION_TOKEN",
            "x-am-user-authorization" to "API_USER_TOKEN",
            "x-aws-authorization" to "AWS_TOKEN",
            "x-google-authorization" to "GOOGLE_TOKEN",
            "x-azure-authorization" to "AZURE_TOKEN",
        )),
)
```

## Multi-tenant
- `instance: "crm::acme"` works on the database of the tenant `acme` of the [multi-tenant](https://docs.apimaker.dev/v4/docs/features/multi-tenant.html) instance `crm`.
- With `instance: "crm"`, the call works on the database of the tenant of the request: a custom API called with the [x-am-tenant-username](https://docs.apimaker.dev/v4/docs/apis-all/header/requestHeader.html#x-am-tenant-username) header passes it on to the APIs it calls. A request without a tenant works on the structure database.

**TypeScript**

**Distinct first names of some customers of the tenant acme**

```typescript
let distinctQuery = await g.sys.db.distinctQuery({
    instance: "crm::acme", database: "crm", collection: "customers",
    distinctField: "first_name",
    find: {
        "last_name": "Lin"
    }
});
```

**Python**

**Distinct first names of some customers of the tenant acme**

```python
distinct_query = await g.sys.db.distinct_query(
    'crm::acme', 'crm', 'customers',
    'first_name',
    find={
        'last_name': 'Lin',
    },
)
```

**PHP**

**Distinct first names of some customers of the tenant acme**

```php
$distinctQuery = $g->sys->db->distinctQuery(
    'crm::acme', 'crm', 'customers',
    'first_name',
    find: [
        'last_name' => 'Lin',
    ],
);
```

**C#**

**Distinct first names of some customers of the tenant acme**

```csharp
var distinctQuery = await g.Sys.Db.DistinctQuery(new Distinct("crm::acme", "crm", "customers", "first_name")
{
    Find = new JsonObject
    {
        ["last_name"] = "Lin",
    },
});
```

**Go**

**Distinct first names of some customers of the tenant acme**

```go
distinctQuery, err := g.Sys.Db.DistinctQuery(am.Distinct{
	Instance: "crm::acme", Database: "crm", Collection: "customers",
	DistinctField: "first_name",
	Find: am.M{
		"last_name": "Lin",
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**Distinct first names of some customers of the tenant acme**

```rust
let distinct_query = g.sys.db.distinct_query(
    Distinct::new("crm::acme", "crm", "customers", "first_name")
        .find(json!({
            "last_name": "Lin",
        })),
)?;
```

**Java**

**Distinct first names of some customers of the tenant acme**

```java
var distinctQuery = g.sys.db.distinctQuery(new Distinct("crm::acme", "crm", "customers", "first_name")
    .find(Map.of(
        "last_name", "Lin"
    )));
```

**Kotlin**

**Distinct first names of some customers of the tenant acme**

```kotlin
val distinctQuery = g.sys.db.distinctQuery(
    Distinct("crm::acme", "crm", "customers", "first_name")
        .find(mapOf(
            "last_name" to "Lin",
        )),
)
```

## Without a schema

`g.sys.db.gen.distinctQueryGen` takes the same arguments and calls the [distinct with query generated API](https://docs.apimaker.dev/v4/docs/apis-all/schema-apis/auto-generated-schema-based-distinct-with-query-api.html#without-a-schema) : no schema, so the data is read and written as it is in the table, without the conversions, validations and defaults of the schema.

| Language | The call |
|---|---|
| TypeScript | `g.sys.db.gen.distinctQueryGen(…)` |
| Python | `g.sys.db.gen.distinct_query_gen(…)` |
| PHP | `$g->sys->db->gen->distinctQueryGen(…)` |
| C#, Go | `g.Sys.Db.Gen.DistinctQueryGen(…)` |
| Rust | `g.sys.db.distinct_query_gen(Distinct::new(…))` |
| Java, Kotlin | `g.sys.db.gen.distinctQueryGen(…)` |

## Related

- [Distinct with query API](https://docs.apimaker.dev/v4/docs/apis-all/schema-apis/auto-generated-schema-based-distinct-with-query-api.html) · [Generated API from code](https://docs.apimaker.dev/v4/examples/sys/db/distinctQuery.html#without-a-schema) · [The global object g](https://docs.apimaker.dev/v4/docs/pre-defined-terms/global-object-g.html)
