SQL:SQL String Operations and Concatenation (|| and LIKE)
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:

ParameterTypeDescription
%WildcardMatches zero or more characters in LIKE.
_WildcardMatches exactly one character in LIKE.

Ready-to-Run Code Example

Executable in Compilra

Run 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

Run and test SQL on Compilra

Execute this code snippet with pre-supplied standard input (stdin) in Compilra’s cloud compiler.

SQL Online Compiler