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

Filter Rows By Pattern With LIKE

Match string columns against a wildcard pattern using `LIKE`.

Docker-validated Not currently validation-green

Find all users with an example.com email address

The % before @example.com matches any username prefix of any length. Carol's test.org address does not match and is excluded. Use ILIKE in PostgreSQL for a case-insensitive pattern match.

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

INSERT INTO
  users (id, email)
VALUES
  (1, 'alice@example.com'),
  (2, 'bob@example.com'),
  (3, 'carol@test.org');
Shared across supported engines.
SQL
SELECT
  id,
  email
FROM
  users
WHERE
  email LIKE '%@example.com'
ORDER BY
  id;
Returned rows for the shared example.
idemail
1alice@example.com
2bob@example.com

Output is identical across all engines.

Where this command helps.

  • searching for rows where a column matches a wildcard pattern
  • finding records by partial string match such as domain or prefix

What the command is doing.

LIKE matches strings using two wildcards: % matches any sequence of zero or more characters, and _ matches exactly one character. It is case-insensitive in MySQL and SQL Server by default, but case-sensitive in PostgreSQL. NOT LIKE excludes matching rows.