// conditional reference

SQL BETWEEN SYMMETRIC operator

BETWEEN that swaps its bounds when the first is larger than the second.

카테고리
조건부
Returns
boolean
In this category
24 of 43

구문

x BETWEEN SYMMETRIC low AND high

엔진 지원

엔진Support메모
SQL Server Not built in No built-in equivalent.
PostgreSQL 예 PostgreSQL 전용
MySQL Not built in No built-in equivalent.
SQLite Not built in No built-in equivalent.
Oracle Not built in No built-in equivalent.

예시

PostgreSQL

SELECT * FROM t WHERE n BETWEEN SYMMETRIC 500 AND 100;

PostgreSQL

SELECT * FROM t WHERE n BETWEEN LEAST(500, 100) AND GREATEST(500, 100);

알아 두면 좋은 정보

  • Plain BETWEEN with reversed bounds is always FALSE; SYMMETRIC normalizes them first.
  • It can hide data bugs: a swapped lower/upper bound that would have returned nothing now silently widens the match.
  • Portable form: x BETWEEN LEAST(a, b) AND GREATEST(a, b), but check your engine's NULL semantics first.

Questions about BETWEEN SYMMETRIC

What does SYMMETRIC mean here?

The bounds are symmetric: the engine swaps them if needed, so low > high still matches the range.

Which engines support it?

PostgreSQL only among the big five; elsewhere use LEAST and GREATEST around the bounds.

Why not always use SYMMETRIC?

It can mask reversed-bound bugs that an empty result would have exposed.

Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.

Cheat sheets for the engines that have it: PostgreSQL.

// fewer lookups

Functions your engine actually has

SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.