---
title: NEAREST_BY_JOIN error condition
description: Documentation for the NEAREST\_BY\_JOIN error condition on Databricks
canonical_url: https://docs.databricks.com/gcp/en/error-messages/nearest-by-join-error-class
---

# NEAREST\_BY\_JOIN error condition

[SQLSTATE: 42604](https://docs.databricks.com/gcp/en/error-messages/sqlstates.md#class-42-syntax-error-or-access-rule-violation)

Invalid nearest-by join.

## CROSS\_JOIN\_NOT\_ENABLED

Nearest-by join is implemented as a bounded cross-product internally and is therefore rejected when `spark.sql.crossJoin.enabled = false`. Set `spark.sql.crossJoin.enabled = true` to permit it, or rewrite the query without nearest-by.

## NON\_ORDERABLE\_RANKING\_EXPRESSION

The ranking expression `<expression>` of type `<type>` is not orderable. Provide an expression that returns an orderable type, such as a numeric distance like abs(a.col - b.col) or a numeric similarity score.

## NUM\_RESULTS\_OUT\_OF\_RANGE

The number of results `<numResults>` must be between `<min>` and `<max>`. Update the literal in `APPROX NEAREST <numResults> BY ...` (or `EXACT NEAREST <numResults> BY ...`) to fall within that range.

## STREAMING\_NOT\_SUPPORTED

Nearest-by join is not supported with streaming DataFrames/Datasets.

## UNSUPPORTED\_DIRECTION

Unsupported nearest-by join direction '`<direction>`'. Supported nearest-by join directions include: `<supported>`.

## UNSUPPORTED\_JOIN\_TYPE

Unsupported nearest-by join type `<joinType>`. Supported types: `<supported>`.

## UNSUPPORTED\_MODE

Unsupported nearest-by join mode '`<mode>`'. Supported modes include: `<supported>`.
