Joining and cutting text
A few more functions cover most everyday jobs:
first_name || ' ' || last_namejoins text together. (CONCAT(first_name, ' ', last_name)does the same.)SUBSTRING(sku, 4, 3)takes 3 characters starting at the 4th: 'PAP' from 'BW-PAP-1004'.REPLACE(phone, ' ', '')swaps every space for nothing.LENGTH(name)counts the characters.
SELECT first_name || ' ' || last_name AS full_name
FROM employeesIn other databases
SELECT first_name || ' ' || last_name, LENGTH(name) FROM employeesSELECT first_name + ' ' + last_name, LEN(name) FROM employeesCONCAT(first_name, ' ', last_name) works too, and treats NULL as empty text.
SELECT CONCAT(first_name, ' ', last_name), CHAR_LENGTH(name) FROM employees|| means OR in MySQL unless it's set up otherwise. LENGTH counts bytes, so é counts twice.
SELECT first_name || ' ' || last_name, LENGTH(name) FROM employeesSELECT CONCAT(first_name, ' ', last_name), LENGTH(name) FROM employees|| works too.