Distinct¶
Lists the different values of a column, or the different combinations of several columns, in the order you ask.
In short
GET /api/schema/<user-path>/<instance>/<database>/<table>/distinct/<column>[/<order>]- Several columns :
distinct/first_name,pincode. - Filter with the query params of get all :
?find={isActive:1}.
| Method | GET |
| URL | /api/schema/admin/mysql8/inventory/customers/distinct/:field[/:order] |
| Body | none |
| Query params | find, a column |
| Answer | data : a list of objects, one for each value or combination |
| Databases | MongoDB, MySQL, MariaDB, PostgreSQL, SQL Server, Oracle, TiDB, Percona |
| Cached | yes, when enableCaching is on for the table or the database |
| From code | g.sys.db.distinct |
| API id | SCHEMA_GET_DISTINCT |
| Without a schema | /api/gen/admin/mysql8/inventory/customers/distinct/:field[/:order] : below |
The examples read the table of get all.
One column¶
{ "success": true, "statusCode": 200, "data": [ { "first_name": "Alice" }, { "first_name": "Bob" }, { "first_name": "Eve" }, { "first_name": "Mallory" } ] }
The order is ascending. For descending, add desc : distinct/first_name/desc. -1, dsc, 0 and false mean descending too. Anything else is ascending.
Several columns¶
{ "success": true, "statusCode": 200, "data": [ { "first_name": "Alice", "pincode": 382346 }, { "first_name": "Bob", "pincode": 382345 }, { "first_name": "Eve", "pincode": 382349 }, { "first_name": "Eve", "pincode": 382348 }, { "first_name": "Mallory", "pincode": 382347 } ] }
One order for each column, in the same place. A missing order is ascending.
With a filter¶
To send the filter in a body, use distinct with query.
Good to know¶
- No column :
Please provide field for distinct API.An unknown column :Invalid column ['nick_name'] found in your field list. - A column the groups of the caller may not read can not be listed.
- When no row has a value in the column,
datais[].
From your code¶
g.sys.db.distinct makes the same call from custom APIs, hooks, events, schedulers and test cases.
Without a schema : /api/gen¶
Every table also answers this operation under /api/gen, with or without a schema :
| URL | /api/gen/admin/mysql8/inventory/customers/distinct/:field[/:order] |
| API id | GEN_GET_DISTINCT |
| From code | g.sys.db.gen.distinctGen |
find matches the type you send. On MongoDB, a text that looks like an ObjectId is turned into one.
Headers and errors¶
This operation takes the request headers of every API. It answers the envelope, with the status codes and the messages of every API.
Related : All APIs · Table schema · Pre hooks · Post hooks · API group permission