Reading — step 1 of 5
Learn
Hello, SQL
SQL is unlike every language in this catalog, and the difference is the entire point: you don't tell the computer how to compute something — you describe the result you want, and a query engine figures out the how. That inversion is why SQL, born in 1974, still runs effectively every application on earth: describe-what-you-want survives every change in how computers actually work.
Your first query
SELECT 'Hello, SQL';
SELECT is the verb of the language — produce these values. It doesn't even need a table: given an expression, it evaluates it and returns a result with one row. A few more freestanding examples:
SELECT 42;
SELECT 6 * 7;
SELECT 'Ada' || ' ' || 'Lovelace'; -- || concatenates strings → 'Ada Lovelace'
Note the quoting rule that trips up everyone arriving from other languages: strings take single quotes ('hello'). Double quotes mean identifiers (table and column names) in SQL. Mixing them up produces confusing "no such column: hello" errors — when you see that error on something you meant as text, check your quotes.
The grammar in one breath
A full query reads almost like the sentence you'd say out loud:
SELECT name, population -- which values to produce
FROM cities -- from which table
WHERE country = 'JP' -- keeping which rows
ORDER BY population DESC -- in what order
LIMIT 3; -- how many
Each clause is a lesson in this course; by chapter 3 you'll write that query fluently. Two mechanical notes now: the semicolon terminates a statement (required by graders, good habit everywhere), and keywords are case-insensitive — select works — but the universal convention is KEYWORDS UPPER, names lower, and following it makes your queries instantly readable to every SQL programmer alive.
What's actually underneath
A relational database is tables (rows × typed columns), and SQL statements fall into two families you'll hear named: DDL (data definition — CREATE TABLE and friends, chapter 1) and DML (data manipulation — SELECT, INSERT, UPDATE, DELETE, the rest of the course). The engine you're using here is SQLite — the most-deployed database in existence (it's in your phone, your browser, your car). Its SQL is standard enough that everything in this course transfers to Postgres and MySQL; where a detail is SQLite-specific, the lesson will say so.
Your exercise
Produce the exact greeting with a SELECT. Graders compare output text exactly, which teaches the right first lesson about SQL: the result of a query is data, and data has an exact shape — down to capitalization and spacing. One string expression, single quotes, semicolon. Welcome to the declarative world.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…