sqlcmd.net validated sql reference
beginner filtering MySQL MariaDB SQL Server PostgreSQL SQLite

Filter Text Case-Insensitively

Compare normalized text values with LOWER or UPPER so matching does not depend on stored capitalization.

Docker-validated Not currently validation-green

Find email addresses regardless of capitalization

Both stored variants of Alice's email normalize to [email protected], so both rows match. Bob's email normalizes to a different value and is excluded.

Rows loaded before the example query runs.
Setup
CREATE TABLE users (id INT, email VARCHAR(100));

INSERT INTO
  users (id, email)
VALUES
  (1, '[email protected]'),
  (2, '[email protected]'),
  (3, '[email protected]');
Shared across supported engines.
SQL
SELECT
  id,
  email
FROM
  users
WHERE
  LOWER(email) = LOWER('[email protected]')
ORDER BY
  id;
Returned rows for the shared example.

The same LOWER-based comparison works across the supported engines.

Where this command helps.

  • finding a user by email address regardless of capitalization
  • matching imported codes that may arrive in inconsistent text case

What the command is doing.

Case sensitivity varies by engine, column collation, and operator. A portable way to perform a case-insensitive equality filter is to normalize both sides of the comparison with LOWER or UPPER. This is useful for user-entered identifiers such as email addresses, usernames, and codes. On large tables, prefer a case-insensitive collation or a functional index when the engine supports it, because wrapping a column in a function can prevent a normal index from being used.