SQL RIGHT

The mirror of LEFT — grabs the last N characters, counting from the end of the string.

What & Why

RIGHT(text, n) returns the last n characters of a string.

See How It Works

BUSINESS QUESTION

Marketing wants the last four characters of every campaign name for a compact label.

idnamechannelspendstart_dateend_datestatustarget_segment
1Spring Launchgoogle_ads55000.002024-01-152024-03-31activesmb
2Retention Webinaremail45000.002024-02-102024-04-15activeenterprise
3Finance Retargetinglinkedin50000.002024-03-122024-05-31activeenterprise
4Enterprise Searchgoogle_ads60000.002024-04-012024-06-30activeenterprise
EXAMPLE QUERY
SELECT
  id AS campaign_id,
  name,
  RIGHT(name, 4) AS name_suffix
FROM marketing.campaigns
ORDER BY campaign_id;
RESULT — exact output from the displayed Queryflo rows
campaign_idnamename_suffix
1Spring Launchunch
2Retention Webinarinar
3Finance Retargetingting
4Enterprise Searcharch

RIGHT returns the final four characters of each campaign name.

Intermediate business practice

Sign up free to try it on a real business scenario