How to Read Rows from a SQLite Table with SELECT
SELECT reads rows from a table. SELECT * returns every column, and a list of column names returns only those. This guide reads a table of books both ways, with real output from SQLite 3.54.1.
Syntax
SELECT * FROM <table>;
SELECT <column 1>, <column 2> FROM <table>;
| Part | What it means |
|---|---|
SELECT * | Every column, in the table's order |
SELECT <column 1>, <column 2> | Only the columns you list, in the order you list them, separated by commas |
FROM <table> | The table to read |
SQLite's documentation on SELECT: "The SELECT statement is used to query the database. The result of a SELECT is zero or more rows of data where each row has a fixed number of columns."
Prerequisites
- The sqlite3 command-line shell. This guide uses SQLite 3.54.1. Run
sqlite3 --versionto see yours; the SQLite download page has the command-line tools for Windows, macOS and Linux.
Step 1: Write the Script
Save this as select_rows.sql:
CREATE TABLE books (
title TEXT NOT NULL,
author TEXT NOT NULL,
pages INTEGER NOT NULL
);
INSERT INTO books (title, author, pages) VALUES ('Emma', 'Jane Austen', 474);
INSERT INTO books (title, author, pages) VALUES ('Persuasion', 'Jane Austen', 249);
INSERT INTO books (title, author, pages) VALUES ('Dune', 'Frank Herbert', 412);
SELECT * FROM books;
SELECT title, pages FROM books;

- The table holds three books.
SELECT * FROM booksasks for every column.SELECT title, pages FROM booksasks for two of them.
Step 2: Run It
In the folder that holds the script, run:
sqlite3 -table library.db ".read select_rows.sql"
sqlite3 opens the database file library.db, and creates it when it isn't there. -table prints each result as a table, and .read runs the statements in the script. The command is the same in bash, zsh and PowerShell.
+------------+---------------+-------+
| title | author | pages |
+------------+---------------+-------+
| Emma | Jane Austen | 474 |
| Persuasion | Jane Austen | 249 |
| Dune | Frank Herbert | 412 |
+------------+---------------+-------+
+------------+-------+
| title | pages |
+------------+-------+
| Emma | 474 |
| Persuasion | 249 |
| Dune | 412 |
+------------+-------+

The first result has all three columns, the second only title and pages. Both hold every row: without a WHERE, a SELECT returns the whole table.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
A comma after the last column, SELECT title, pages, FROM books | near "FROM": syntax error | No comma before FROM |
A misspelled column, SELECT titel FROM books | no such column: titel | Check the column names with .schema books |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
no such table: bookz | The table name is misspelled, or the table is in another database file | List the tables with .tables, which printed books here |
Parse error near line 1 of select_rows.sql: table books already exists | The script already ran on library.db | Delete library.db and run the script again |
FAQ
Can SELECT work without a table?
Yes. Without FROM, it works out its expressions once: SELECT 2 + 3; returned 5.
In what order do the rows come back?
Without ORDER BY, there's no promised order. The documentation: "If a SELECT statement that returns more than one row does not have an ORDER BY clause, the order in which the rows are returned is undefined."
Conclusion
SELECT * FROM books returned every column of the three books, and SELECT title, pages FROM books returned only the two that were named.
Additional Resources
- SELECT — the full statement.
- The result columns — how SQLite works out the columns of a result.
