SQLMarrow / Course Academy Experience

SQL & Databases Masterclass Course

Welcome to the ultimate postgresql tutorial for beginners 2026. Work through interactive sql practice problems with solutions, master our comprehensive sql window functions tutorial modules, and prepare for tough sql interview questions at Google and Amazon entirely in your browser. Claim your course completion XP and build production-ready database mastery today!

COURSE PROGRESS
0%
0 of 40 Modules Solved
COURSE SYLLABUS
40 Lessons
LESSON WORKSPACEIntermediate

SQL String Functions: Clean & Manipulate Data

Introduction & Core Concept

Textual data entered by customers is notoriously inconsistent. Users mix uppercase and lowercase letters, insert accidental leading spaces, or combine multiple details into single fields. SQL provides robust string formatting cleaners to normalize text instantly.

SELECT UPPER(name), SUBSTR(phone, 1, 3) FROM users;
Core String Cleaners
  • UPPER(string) / LOWER(string): Converts entire text strings to uppercase or lowercase.
  • SUBSTR(string, start, length): Extracts specific substring slices based on character index pointers.
  • > 💡 MSSQL Tip: In Microsoft SQL Server (MSSQL), the function is named SUBSTRING() instead of SUBSTR()! For example: SUBSTRING(phone, 1, 3).

  • || (Concatenation Operator in SQLite): Merges multiple text variables into a single unified string.
  • > 💡 MSSQL Tip: In Microsoft SQL Server (MSSQL), you use the + operator instead of || to join strings! For example: 'Hello ' + 'World'.

  • TRIM(string): Strips unwanted leading and trailing whitespace.
  • Why & Where We Use It
  • Why We Use It: Prevents duplicate record creation. If one user registers as 'john doe' and another as 'John Doe', standardizing on LOWER() ensures systems recognize them as identical entities.
  • Where We Use It: Generating user system slugs, standardizing postal codes, cleaning phone numbers, and formatting addresses.
  • Real-World Example

    ShopMart wants to generate standardized system identification slugs for every customer by combining the prefix 'USER-', their numerical ID, and their 3-digit country ISO code in uppercase.

    Best Practices: What to Do & What NOT to Do
  • What to Do: Always run TRIM(LOWER(column)) when matching text columns from disparate third-party systems to ensure invisible trailing whitespace doesn't break your JOIN conditions.
  • What NOT to Do: Avoid performing heavy string manipulation inside your WHERE join predicates if you can avoid it, as doing so bypasses standard index searches.
  • Syntax & Pro Tips
    SELECT 'USER-' || id || '-' || UPPER(country) AS slug FROM users;
    Interactive Sandboxed Terminal (Preloaded DB Schema: SHOPMART)
    SQL Query WorkspaceSQLite v3.45 (WASM Mode)
    QUICK INSERT:
    1