Excel to SQL · Lesson 11 of 12
Text functions: LEFT, CONCAT, UPPER, FIND
Most Excel text formulas have a SQL twin. The names on this site follow SQLite, which is what runs in your browser:
substr(text, start, length)is MID (and LEFT when start is 1)length(text)is LENupper()andlower()are UPPER and LOWERa || ' ' || bjoins text, like&in Excelreplace(text, 'old', 'new')is SUBSTITUTEinstr(text, '@')is FIND
Try itEdit the query, then Run
| name | shouting | email_domain | label |
|---|---|---|---|
| Kavya Haddad | KAVYA HADDAD | example.com | Kavya Haddad (United States) |
| Ben Kim | BEN KIM | example.com | Ben Kim (India) |
| Kavya Kim | KAVYA KIM | example.com | Kavya Kim (India) |
| Nikhil Tanaka | NIKHIL TANAKA | example.com | Nikhil Tanaka (Nigeria) |
| Elena Nguyen | ELENA NGUYEN | example.com | Elena Nguyen (United Kingdom) |
| Leo Garcia | LEO GARCIA | example.com | Leo Garcia (Nigeria) |
| Tara Ali | TARA ALI | example.com | Tara Ali (Germany) |
| Quinn Lopez | QUINN LOPEZ | example.com | Quinn Lopez (United States) |
| Sam Okafor | SAM OKAFOR | example.com | Sam Okafor (Brazil) |
| Ben Smith | BEN SMITH | example.com | Ben Smith (United States) |
10 rows
Other databases spell a few of these differently (Postgres has left() and position(), SQL Server uses + to join text), but the ideas are identical.
Your turn
Show each customer's name and the first name only, as first_name (everything before the space).
instr(name, ' ') finds the space. Take substr from 1 up to one before it.
This page on one card
