The expressions 1=0 and 1=1 are commonly used in SQL across many databases. Nearly all relational database management systems (RDBMS) support them. This is because they adhere to standard SQL logic.

Why use 1 0 and 1 1 in sql queries example
Photo by Pixabay on Pexels.com

Why use 1=0 and 1=1 in SQL Queries Example

  1. Why use 1=0 and 1=1 in SQL Queries Example
    1. Where 1=0 in SQL example
    2. Where 1=0 in SQL
    3. Supported databases

Where 1=0 in SQL example

  • 1=0: This condition is always false. It is often used to prevent any rows from being returned or affected. For instance, creating an empty result set.
SELECT * FROM table WHERE 1=0; -- Always returns no rows

Where 1=0 in SQL

  • 1=1: This condition is always true. It’s sometimes used in dynamic SQL to make it easier to append extra AND conditions. For example:
SELECT * FROM table WHERE 1=1 AND column = 'value'; -- Always returns rows matching the column condition

Supported databases

Most RDBMS support these expressions:

  • MySQL
  • PostgreSQL
  • Microsoft SQL Server
  • Oracle
  • SQLite
  • MariaDB
  • IBM Db2

These conditions rely on basic boolean logic, which all SQL engines handle. So, it’s a universal SQL feature, not specific to any particular database engine.