SQL•String Matching
SQL String Operations and Concatenation (|| and LIKE)
Learn SQL wildcard matching with LIKE and string operations (UPPER, LOWER, LENGTH, SUBSTR).
Syntax
SELECT * FROM table WHERE email LIKE '%@compilra.dev';
Parameters & Values
Key components and acceptable values for this structure:
| Parameter | Type | Description |
|---|---|---|
| % | Wildcard | Matches zero or more characters in LIKE. |
| _ | Wildcard | Matches exactly one character in LIKE. |
Ready-to-Run Code Example
Executable in CompilraRun this complete, working example directly without installing SQL locally:
CREATE TABLE employees (
id INTEGER PRIMARY KEY,
first_name TEXT,
last_name TEXT,
email TEXT
);
INSERT INTO employees VALUES
(1, 'Alex', 'Chen', '[email protected]'),
(2, 'Sarah', 'Miller', '[email protected]'),
(3, 'David', 'Kim', '[email protected]');
-- String concatenation with || and pattern matching with LIKE
SELECT
first_name || ' ' || last_name AS full_name,
UPPER(email) AS upper_email
FROM employees
WHERE email LIKE '%@compilra.dev';Expected Output:
full_name upper_email --------- ------------------- Alex Chen [email protected] David Kim [email protected]
How It Works: Step-by-Step
- Lines 8-11: Inserts employee records with different email domains.
- Lines 14-17: || concatenates first and last names; LIKE finds compilra.dev addresses.
Key Concepts
- || is standard SQL concatenation operator (supported in SQLite, PostgreSQL, Oracle).
- LIKE is case-insensitive in SQLite by default for ASCII characters.
Common Mistake: Using double quotes "text" instead of single quotes 'text' for strings
In standard SQL, double quotes denote identifiers (column/table names); single quotes denote string literals.
❌ Incorrect
WHERE email = "test"; // Treated as column name in standard SQL!
✅ Correct
WHERE email = 'test'; // Valid string literal
Related SQL Tutorials & Compiler
SQL WHERE Filtering: Comparison and Logical Operators (AND, OR, IN)
Filter records using the WHERE clause with comparison, AND, OR, NOT, IN, and BETWEEN.
SQL Session-Level Variable Mapping Constraints and CTE Declarations
Define and map session-level variables, CTE bind parameters, and column expressions in SQL queries.
SQL Dynamic Transactional CASE WHEN Metrics Query Logic
Implement dynamic transactional business logic and classification metrics in SQL using CASE WHEN expressions.
SQL Online Compiler
Open in Compilra IDE
Run and test SQL on Compilra
Execute this code snippet with pre-supplied standard input (stdin) in Compilra’s cloud compiler.