Hello World (first programs) · Beginner · 13 min
Hello World in SQL with SQLite: your first SELECT and table
By Padding · Updated 18 Nov 2026
Ubuntu 26.04 · SQLite 3.46.1 (Ubuntu package) · upstream SQLite 3.54.1
You will install the SQLite shell, run your first SELECT, create and query a small table with WHERE and ORDER BY, then run the same statements from a .sql file and see that the whole database is one file on disk.
On this page
SQL is the language you use to ask a relational database for data. It is different from most languages you will meet: you do not write the steps to find an answer, you describe the answer you want ("the messages that are not in English, sorted by language") and the database engine works out how to get it. That is what people mean when they call SQL declarative.
You will learn SQL here with SQLite. Most databases, such as PostgreSQL and MySQL, run as a server that programs connect to. SQLite has no server: it is a library, and a database is a single ordinary file. That makes it the quickest way to start, and it is far from a toy. SQLite is built into every Android and iPhone, most web browsers and many desktop apps. On Android it is how apps keep data on the phone, so they still work when your data bundle runs out or the signal drops.
You work in a throwaway folder, ~/hello-sql-demo, and delete it at the end.
Step 1 · Install the sqlite3 shell
The sqlite3 program is a small shell: you type SQL into it, and it prints the results. On Ubuntu 26.04 install it from the Ubuntu archive:
sudo apt update
sudo apt install -y sqlite3
sqlite3 --versionUbuntu 26.04 installs SQLite 3.46.1. The newest upstream release is 3.54.1, from October 2026. Everything in this tutorial works the same on both.
On macOS, a sqlite3 program already comes with the system; open Terminal and run sqlite3 --version to check. On Windows, either use WSL and follow the Ubuntu commands, or download the "sqlite-tools" zip for Windows from sqlite.org/download.html, unzip it into a folder, and run sqlite3.exe from that folder in PowerShell.
Check it worked
sqlite3 --version prints one line that starts with the version number and a date, something like 3.46.1 2024-08-13 .... If you see sqlite3: command not found, the install did not finish; run the apt install line again and read the last lines for an error.
Step 2 · Say hello with SELECT
Start the shell with no file name. It opens a temporary database that lives only in memory:
sqlite3You see a short banner and the prompt sqlite>. Type this line and press Enter:
SELECT 'Hello, World!';The shell prints Hello, World!. Type .quit to leave. Here is what each part of that line means:
SELECTasks the database to return a result. Most of the time it reads from a table, but it can also return a value you give it directly, as here.'Hello, World!'is a string, a piece of text. In SQL, strings go in single quotes. Double quotes mean something else (a column or table name), which is one of the mistakes covered later.;ends the statement. Without it the shell waits for more input.
SQL keywords are not case-sensitive, so select works too. Writing them in capitals is a convention that makes the keywords easy to tell apart from your own names.
You can also pass a statement on the command line. The shell runs it and exits, which is handy in scripts:
sqlite3 :memory: "SELECT 'Hello, World!';":memory: is a special name that means "a database in memory, not in a file".
Check it worked
Both the interactive shell and the one-line command print exactly Hello, World!, without quotes. If the interactive shell shows ...> instead of a result, it is waiting for the semicolon: type ; and press Enter.
Step 3 · Create a table and add rows
A table holds rows of data, and every row has the same columns. Make the demo folder and open a database file called hello.db. SQLite creates the file the first time you write to it:
mkdir -p ~/hello-sql-democd ~/hello-sql-demo
sqlite3 hello.dbAt the sqlite> prompt, paste these statements:
CREATE TABLE greetings (
id INTEGER PRIMARY KEY,
language TEXT NOT NULL,
message TEXT NOT NULL
);
INSERT INTO greetings (language, message) VALUES ('English', 'Hello, World!');
INSERT INTO greetings (language, message) VALUES ('Hausa', 'Sannu, duniya!');
INSERT INTO greetings (language, message) VALUES ('Swahili', 'Habari, dunia!');What each part does:
CREATE TABLE greetings (...)makes a table namedgreetingswith three columns, listed between the brackets and separated by commas.id INTEGER PRIMARY KEYis a whole-number column that identifies each row. In SQLite, a column declared exactly this way is filled in for you: the first row gets 1, the next 2, and so on.language TEXT NOT NULLis a text column that must always have a value.NOT NULLmakes the database refuse a row without one.INSERT INTO greetings (language, message) VALUES (...)adds one row. The first list names the columns you are filling, and the second gives the values in the same order. You leave outidso SQLite picks it.
SQLite stores text as UTF-8, so messages in any language, with any accents or script, are stored as you type them.
Check it worked
Still in the shell, type .tables. It prints greetings. Type .schema greetings and it prints the CREATE TABLE statement back to you. Dot-commands like these belong to the sqlite3 shell, not to SQL, which is why they have no semicolon.
Step 4 · Ask questions with WHERE and ORDER BY
Now read the rows back. First turn on column headers and the plain list layout, so the output is the same on every SQLite version:
.headers on
.mode list
SELECT id, language, message FROM greetings;The shell prints a header line and then one line per row, with | between the columns:
id|language|message
1|English|Hello, World!
2|Hausa|Sannu, duniya!
3|Swahili|Habari, dunia!FROM greetings says which table to read, and the list after SELECT says which columns you want, in the order you want them. Next, ask for only some rows and choose their order:
SELECT language, message
FROM greetings
WHERE language <> 'English'
ORDER BY language DESC;WHERE language <> 'English'keeps only the rows where the condition is true.<>means "not equal to";=means "equal to".ORDER BY language DESCsorts the result by language, from Z to A. Leave outDESC(or writeASC) to sort A to Z. WithoutORDER BY, SQL makes no promise about row order, so add it whenever order matters.- One statement can span several lines. The semicolon, not the line break, ends it.
Notice what you did not write: no loop over the rows, no comparison code, no sorting routine. You described the result, and SQLite decided how to produce it.
Type .quit to leave the shell.
Check it worked
The second query prints three lines: the header language|message, then Swahili|Habari, dunia!, then Hausa|Sannu, duniya!. The English row is gone, and Swahili comes before Hausa because of DESC.
Step 5 · Run SQL from a file
Typing into the shell is good for exploring. For anything you want to repeat, put the statements in a file. Create hello.sql:
cd ~/hello-sql-demo
cat > hello.sql <<'SQL'
DROP TABLE IF EXISTS greetings;
CREATE TABLE greetings (
id INTEGER PRIMARY KEY,
language TEXT NOT NULL,
message TEXT NOT NULL
);
INSERT INTO greetings (language, message) VALUES
('English', 'Hello, World!'),
('Hausa', 'Sannu, duniya!'),
('Swahili', 'Habari, dunia!');
.headers on
.mode list
SELECT count(*) AS total FROM greetings;
SELECT language, message FROM greetings WHERE language <> 'English' ORDER BY language;
SQLTwo things are new. DROP TABLE IF EXISTS greetings; deletes the table if it is already there, so you can run the file as many times as you like and always start from the same three rows. The single INSERT adds several rows at once, one bracketed list per row, separated by commas. count(*) counts the rows, and AS total names that result column.
Run the file by sending it into the shell with <:
cd ~/hello-sql-demo
sqlite3 hello.db < hello.sqlThen look at what is in the folder:
cd ~/hello-sql-demo
ls -l
head -c 15 hello.db; echoCheck it worked
The run prints total and 3, then language|message, Hausa|Sannu, duniya! and Swahili|Habari, dunia!. Run it a second time and the total is still 3, because the file starts by dropping the table. ls -l shows hello.db next to hello.sql, a few kilobytes in size, and head prints SQLite format 3, the text every SQLite database file starts with. That file is the whole database: copy it to another computer, or attach it to a message, and it opens there with all its rows.
Step 6 · Take the same SQL to PostgreSQL
The SQL you wrote is not tied to SQLite. The SELECT ... FROM ... WHERE ... ORDER BY statements run unchanged in PostgreSQL, MySQL, SQL Server and the other relational databases, because they follow the SQL standard. If you install PostgreSQL 18 and open psql, SELECT 'Hello, World!'; prints the same text, in a small table with a column header.
The differences show up in table definitions and in the shell commands:
- PostgreSQL does not fill in
id INTEGER PRIMARY KEYfor you. There you writeid integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY. - SQLite is relaxed about types. By default it will store text in an
INTEGERcolumn without complaint. PostgreSQL refuses, which catches mistakes earlier. - Dot-commands such as
.tablesand.modeonly exist insqlite3. Inpsqlthe equivalents start with a backslash, for example\dtto list tables.
Check it worked
Open hello.sql in your editor and find the lines that are SQL statements and the lines that are dot-commands. Only the dot-command lines (.headers on, .mode list) and the id INTEGER PRIMARY KEY line would need to change for PostgreSQL.
Step 7 · Fix the mistakes beginners hit
Run a query against a table name with a typo, to see what an error looks like:
cd ~/hello-sql-demo
sqlite3 hello.db "SELECT * FROM greeting;" || echo "exit status $?"The shell prints an error that names the problem, something like Parse error: no such table: greeting, and exits with a non-zero status. Read the last words of an SQL error first: they usually name the exact table, column or word it could not understand.
The other mistakes you will meet in your first week:
- Forgetting the semicolon. In the interactive shell the prompt changes to
...>and nothing happens. Type;and press Enter. - Double quotes around text.
SELECT "Hello";is wrong in standard SQL: double quotes name a column or table. SQLite sometimes accepts it for compatibility with old code, depending on how it was built, but PostgreSQL fails with an error about a column namedHello. Use single quotes for text every time. - An apostrophe inside a string.
'Ade's report'ends the string early. Write the apostrophe twice:'Ade''s report'. - Missing commas. Columns in
CREATE TABLEand inSELECTlists need commas between them, and none after the last one. - Expecting a fixed order without
ORDER BY. Rows often come back in the order you inserted them, until one day they do not.
When you have finished, delete the demo folder:
cd ~
rm -rf ~/hello-sql-demoCheck it worked
The typo query printed an error mentioning no such table: greeting and then exit status 1. After the clean-up, ls ~/hello-sql-demo reports that there is no such file or directory.
Next steps
SQL is used in every relational database, in data analysis (spreadsheets that outgrow themselves usually end up in SQL) and in the back end of most web and mobile apps.
- Move to a server database: install PostgreSQL 18 on Ubuntu 26.04.
- Once your tables grow, learn how the engine plans a query: speed up slow Postgres queries with EXPLAIN.
- Query a database from a program: start with Hello World in Python, whose standard library includes the
sqlite3module.
Part of these paths
Related tutorials
- How to Install PostgreSQL 18 on Ubuntu 26.04 and Create Your First DatabaseYou will install PostgreSQL 18 from the official PostgreSQL apt repository, create a database and a user for your app, and connect to it with a password.
- How to Find and Fix Slow PostgreSQL Queries with EXPLAIN ANALYZEYou will read a PostgreSQL 18 query plan, add an index that turns a 40 ms table scan into a 0.2 ms lookup, and use pg_stat_statements to find which queries deserve that effort.
- Hello World in Python: the interpreter, input and your first scriptYou will print Hello World in the Python 3.15 interpreter, save and run it as a script, greet a person by name from the keyboard and from the command line, and know what Python does with your file when it runs.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials