Displaying Two Columns as One

Another function (concatenate) allows you to put expressions together. It is represented as a double pipe (||). The syntax looks like this:

char_expr || char_expr

For example, you can concatenate first and last names into one string:

SQL
select au_fname  || au_lname as Writer
from authors
where state > 'CA'
Writer
========================================================
AlbertRinger
AnneRinger
MichelDeFrance
SylviaPanteley
MorningstarGreene
Innesdel Castillo
ReginaldBlotchet-Halls
MeanderSmith
[8 rows]

To make the names more readable, add a space in quotes after the first name and another concatenation symbol after the space:

SQL
select au_fname || ' '  || au_lname as Writer from authors where state > 'CA' Writer ...

Get Practical SQL Handbook, The: Using SQL Variants, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.