SQL: JOINS - Advanced SQL Commands - String Function and Operators

String Functions

The String functions examine and manipulate string values. More information on String Functions and Operators

Syntax:

-- String Function
SELECT column_1 || column_2 as new_column
FROM table_1;

Example: Concatenate the first name and last name columns in the customer table

-- Concatenate the first name and last name columns in the customer table
SELECT first_name || ' ' || last_name  AS full_name
FROM customer
limit 20;
##           full_name
## 1         Jared Ely
## 2        Mary Smith
## 3  Patricia Johnson
## 4    Linda Williams
## 5     Barbara Jones
## 6   Elizabeth Brown
## 7    Jennifer Davis
## 8      Maria Miller
## 9      Susan Wilson
## 10   Margaret Moore
## 11   Dorothy Taylor
## 12    Lisa Anderson
## 13     Nancy Thomas
## 14    Karen Jackson
## 15      Betty White
## 16     Helen Harris
## 17    Sandra Martin
## 18   Donna Thompson
## 19     Carol Garcia
## 20    Ruth Martinez

Example: Return the uppercase of the first and last names

-- Return the uppercase of the first and last names
SELECT upper(first_name), upper(last_name)
FROM customer
limit 20;
##        upper    upper
## 1      JARED      ELY
## 2       MARY    SMITH
## 3   PATRICIA  JOHNSON
## 4      LINDA WILLIAMS
## 5    BARBARA    JONES
## 6  ELIZABETH    BROWN
## 7   JENNIFER    DAVIS
## 8      MARIA   MILLER
## 9      SUSAN   WILSON
## 10  MARGARET    MOORE
## 11   DOROTHY   TAYLOR
## 12      LISA ANDERSON
## 13     NANCY   THOMAS
## 14     KAREN  JACKSON
## 15     BETTY    WHITE
## 16     HELEN   HARRIS
## 17    SANDRA   MARTIN
## 18     DONNA THOMPSON
## 19     CAROL   GARCIA
## 20      RUTH MARTINEZ