SUBSTRING Function in SQL
Level 366 keystrokes
SUBSTRING extracts a portion of a string from a specified position.
SQL code
-- Return each user's name and the start of their email1SELECT2 name, -- SUBSTRING(string, start, length): positions start at 1, not 0 -- Take the first 10 characters of email, e.g. 'alice@exam'3 SUBSTRING(email, 1, 10) AS prefix4FROM5 users-- Return at most 5 rows; without ORDER BY, which rows come back is not guaranteed6LIMIT7 5;Output
+-------+------------+ | name | prefix | +-------+------------+ | Alice | alice@exam | | Bob | bob@exampl | | Carol | carol@test | +-------+------------+ 3 rows in set
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this SQL code and how often they appear.
,× 3;× 1(× 1)× 1