> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # Method name: distinct(propertyName: string, options: WixDataQueryOptions) # Method package: wixData # Method menu location: wixData --> WixDataQuery --> distinct # Method Link: https://dev.wix.com/docs/velo/apis/wix-data/wix-data-query/distinct.md # Method Description: Returns the distinct values that match the query, without duplicates. The `distinct()` function returns a Promise that resolves to: + The distinct values found in the specified field when running the query. + Additional information about the results, such as the number of values that match the query. Unlike `find()`, which returns all item objects that match the query, `distinct()` returns matching field values, and eliminates duplicate field values from the query result. You cannot use `find()` and `distinct()` together. For an item to be resolved as distinct, only the specified field must be distinct. Other fields for that item in the collection are not evaluated when resolving the promise. The Promise is rejected if `distinct()` is called with incorrect permissions or if any of the functions used to refine the query is invalid. > **Notes:** > - Only site visitors with [Data Read](https://support.wix.com/en/article/collection-permissions-an-overview#permissions) permissions can retrieve and view data. You can override the permissions by setting the `suppressAuth` option to `true`. - `distinct()` returns the full distinct items that match the query. To specify which fields to return for each retrieved item, use the `fields()` method. # Method Code Examples: *** Note: do not assume any prop names or enum values other than the ones in the example. ## Get distinct values from a query ```javascript query.distinct("state") .then((results) => { if(results.items.length > 0) { let items = results.items; let firstItem = items[0]; let totalCount = results.totalCount; let pageSize = results.pageSize; let currentPage = results.currentPage; let totalPages = results.totalPages; let hasNext = results.hasNext(); let hasPrev = results.hasPrev(); let length = results.length; let query = results.query; } else { // handle case where no matching items found } }) .catch((error) => { let errorMsg = error.message; let code = error.code; }); ``` ## Create a distinct query and run it ```javascript import wixData from 'wix-data'; // ... wixData.query("myCollection") .distinct("state") .then((results) => { if(results.items.length > 0) { let items = results.items; let firstItem = items[0]; let totalCount = results.totalCount; let pageSize = results.pageSize; let currentPage = results.currentPage; let totalPages = results.totalPages; let hasNext = results.hasNext(); let hasPrev = results.hasPrev(); let length = results.length; let query = results.query; } else { // handle case where no matching items found } }) .catch((error) => { let errorMsg = error.message; let code = error.code; }); ``` ## Create a query, add functions to the query, and find distinct values ```javascript import wixData from 'wix-data'; // ... wixData.query("myCollection") .eq("status", "active") .gt("age", 25) .distinct("state") .then((results) => { if (results.items.length > 0) { let items = results.items; let firstItem = items[0]; let totalCount = results.totalCount; let pageSize = results.pageSize; let currentPage = results.currentPage; let totalPages = results.totalPages; let hasNext = results.hasNext(); let hasPrev = results.hasPrev(); let length = results.length; let query = results.query; } else { // handle case where no matching items found } }) .catch((error) => { let errorMsg = error.message; let code = error.code; }); ``` ## Create a distinct query with options and run it ```javascript import wixData from 'wix-data'; // ... let options = { "suppressAuth": true }; wixData.query("myCollection") .distinct("state", options) .then((results) => { if(results.items.length > 0) { let items = results.items; let firstItem = items[0]; } else { // handle case where no matching items found } }) .catch((error) => { let errorMsg = error.message; let code = error.code; }); ``` ---