Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP C C++ C# AWS W3.CSS HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL SQLITE MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST DART PLAYWRIGHT TOOLS MATH SHEETS POWER BI

SQLite Tutorial

SQLite HOME SQLite Intro SQLite Get Started

SQLite SQL

SQLite SQL SQLite SELECT SQLite SELECT DISTINCT SQLite WHERE SQLite ORDER BY SQLite AND SQLite OR SQLite NOT SQLite INSERT INTO SQLite NULL Values SQLite UPDATE SQLite DELETE SQLite LIMIT SQLite Aggregate SQLite MIN() and MAX() SQLite COUNT() SQLite SUM() SQLite AVG() SQLite LIKE SQLite Wildcards SQLite GLOB SQLite IN SQLite BETWEEN SQLite Aliases SQLite Joins SQLite INNER JOIN SQLite LEFT JOIN SQLite RIGHT JOIN SQLite FULL JOIN SQLite CROSS JOIN SQLite Self Join SQLite UNION SQLite UNION ALL SQLite INTERSECT and EXCEPT SQLite GROUP BY SQLite HAVING SQLite EXISTS SQLite Subqueries SQLite INSERT INTO SELECT SQLite CASE SQLite NULL Functions SQLite Comments SQLite Operators

SQLite Advanced

SQLite UPSERT SQLite RETURNING SQLite WITH (CTE) SQLite Window Functions SQLite JSON

SQLite Database

SQLite Create DB SQLite Attach DB SQLite Create Table SQLite Drop Table SQLite Alter Table SQLite Data Types SQLite STRICT Tables SQLite Constraints SQLite NOT NULL SQLite UNIQUE SQLite PRIMARY KEY SQLite FOREIGN KEY SQLite CHECK SQLite DEFAULT SQLite AUTOINCREMENT SQLite Generated Columns SQLite Create Index SQLite Views SQLite Triggers SQLite Dates SQLite Transactions SQLite PRAGMA SQLite Injection

SQLite Tools

SQLite Command Line SQLite Import and Export SQLite with Python

SQLite References

SQLite Functions

SQLite Exercises

SQLite Editor SQLite Quiz SQLite Exercises

SQLite Get Started


Share

Try SQLite in Your Browser

The easiest way to start using SQLite is with our online editor.

It runs SQLite in your browser, so there is nothing to install:

Example

Select all the products:

SELECT * FROM Products;
Try it Yourself »

The Northwind Database

The examples in this tutorial use the Northwind sample database. It has these tables:

TableRecordsContains
Customers91The customers of the company
Orders196The orders from the customers
OrderDetails518The products in each order
Products77The products the company sells
Categories8The product categories
Suppliers29The companies that make the products
Shippers3The companies that deliver the orders
Employees10The employees of the company

Tip: In the editor, click a table name in the "Your Database" list to see all the records in that table.



Install SQLite on Your Computer

To use SQLite on your own computer, you need the sqlite3 command line program:

  • Windows: Go to the download page at sqlite.org, and download the zip file with the command line tools (sqlite-tools). Unzip it, and run sqlite3.exe
  • macOS: SQLite is already installed. Open the Terminal, and type sqlite3
  • Linux: SQLite is often installed already. On Ubuntu and Debian, you can install it with sudo apt install sqlite3

Create Your First Database

Start sqlite3 with a file name. If the file does not exist, SQLite creates a new, empty database:

sqlite3 shop.db

Now you can type SQL statements. End each statement with a semicolon:

sqlite> CREATE TABLE Friends (Name TEXT, Age INTEGER);
sqlite> INSERT INTO Friends VALUES ('Emil', 30);
sqlite> SELECT * FROM Friends;
Emil|30
sqlite> .quit

.quit closes sqlite3. The data is saved in the file shop.db, and is still there the next time you open it.

You will learn more about sqlite3 in the SQLite Command Line chapter.


Download the Northwind Database

You can also download the Northwind database, and run the examples from this tutorial on your own computer:

Download northwind.zip

Unzip the file, and open the database with sqlite3:

sqlite3 northwind.db

SQLite in Python

SQLite is built into Python, in the sqlite3 module, so you can use the Northwind database from Python too.

If you have downloaded the Northwind database, put the file northwind.db in the same folder as your Python file. Then write this code in a file, for example mydatabase.py, and run it from that folder with python mydatabase.py:

Example

Select the customers from the UK:

import sqlite3

con = sqlite3.connect("northwind.db")
cur = con.cursor()

cur.execute("""
  SELECT CustomerName, City
  FROM Customers
  WHERE Country = 'UK'
""")
for row in cur.fetchall():
  print(row)

con.close()
Run Example »

You will learn more in the SQLite with Python chapter, and step by step in the Python SQLite chapter of our Python Tutorial.

In the rest of this tutorial, we will use our SQLite online editor in all the examples.




Free account

Track your progress

XP earned 0 Day streak 0 Spaces 0 League —

New

Learn in Adventure Mode W3Schools Adventure App

Coding fundamentals as bite-sized lessons and challenges.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by W3Schools. All Rights Reserved. W3Schools is Powered by W3.CSS.