Learn SQL/Intermediate/String Functions/SQL String Concatenation (||)

SQL String Concatenation (||)

The operator form of joining text together — shorter to type than CONCAT, but propagates NULL through the whole expression.

What & Why

The || operator joins text values together, functioning like CONCAT for ordinary values — the difference only shows up when NULL is involved, covered in the previous lesson.

See How It Works

BUSINESS QUESTION

Product wants a readable feature and team label.

idnamedescriptionteamreleased_atdeprecated_at
1Activation ChecklistGuides new users through setupgrowth2024-01-20NULL
2CSV ExportExports report dataplatform2024-02-14NULL
3Invite NudgesPrompts workspace collaborationgrowth2024-03-05NULL
4Legacy DashboardOriginal reporting surfaceanalytics2023-08-102024-06-01
EXAMPLE QUERY
SELECT
  id AS feature_id,
  name || ' — ' || team AS feature_label
FROM product.features
ORDER BY feature_id;
RESULT — exact output from the displayed Queryflo rows
feature_idfeature_label
1Activation Checklist — growth
2CSV Export — platform
3Invite Nudges — growth
4Legacy Dashboard — analytics

The concatenation uses each displayed feature name and team.

Now You Try

Practice this concept

Product wants a readable feature and team label.

Available schema
product

Prefix tables with product.table_name.

feature_idfeature_label
product.features
ColumnType
idinteger
nametext
descriptiontext
teamtext
released_attimestamp with time zone
deprecated_attimestamp with time zone
internal_priorityinteger
query.sql
Intermediate business practice

Sign up free to try it on a real business scenario