0PricingLogin
SQL Academy · Lesson

Concatenation: || and CONCAT

Concatenate strings with the || operator and CONCAT(), and understand how each handles NULL inputs.

Standard Concatenation: ||

The SQL-standard operator for joining strings is ||:

SELECT first_name || ' ' || last_name AS full_name FROM users;
SELECT 'Hello, ' || name || '!' FROM users;

|| with NULL = NULL

If any operand is NULL, the whole expression becomes NULL. Be explicit:

SELECT first_name || ' ' || NULL;     -- NULL

-- Defend with COALESCE:
SELECT first_name || ' ' || COALESCE(last_name, '') FROM users;

All lessons in this course

  1. Concatenation: || and CONCAT
  2. UPPER, LOWER, SUBSTRING, REPLACE
  3. TRIM, LPAD, RPAD
  4. Full-Text Search Introduction (tsvector, to_tsquery)
← Back to SQL Academy