Displaying One Column as Two

Sometimes data stored in the database as one column make more sense to users when it appears as two or more separate displays. This is particularly true when the column consists of data that seem to be of mixed types, as in some composite identification fields (a health insurance number, for example, may consist of the familiar nine-digit Social Security number plus an alphabetic company or geographic code).

In the titles table, the title_id column comes close to this situation. It contains six characters: two letters followed by four digits. Here's some sample data (the WHERE clause limits the rows returned):

SQL
select title_id
from titles
where price > 29.99
title_id
========
PC8888
PC1035
TC3218
PS1372 [4 rows] ...

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.