Practical exercises
Let’s now practice what we've learned in this chapter with some exercises.
Practical exercise 1
Let’s look at multiple SQL string functions in one SQL query:
SELECT LENGTH(last_name) as "Length", CONCAT(first_name, ' ', last_name) as "Full Name", SUBSTRING(first_name, 1, 1) as "Initial", REPLACE(email, '@example.com', '') as "Username", UPPER(last_name) as "Last Name (Uppercase)" FROM users WHERE LOWER(first_name) = 'john';
This statement selects the length of the last_name
column, the concatenation of the first_name
and last_name
columns as "Full Name"
, the first character of the first_name
column as "Initial"
, the email
column with the @example.com
domain removed...