PYnative

Python Programming

  • Learn Python
    • Python Tutorials
    • Python Basics
    • Python Interview Q&As
  • Exercises
    • Python Exercises
    • C Programming Exercises
    • C++ Exercises
  • Quizzes
  • Code Editor
    • Online Python Code Editor
    • Online C Compiler
    • Online C++ Compiler
Home » Python » Databases » Python Select from SQLite Table

Python Select from SQLite Table

Updated on: March 9, 2021 | 10 Comments

This lesson demonstrates how to execute SQLite SELECT Query from Python to retrieve rows from the SQLite table using the built-in module sqlite3.

Goals of this lesson

  • Fetch all rows using a cursor.fetchall()
  • Use cursor.fetchmany(size) to fetch limited rows, and fetch only a single row using cursor.fetchone()
  • Use the Python variables in the SQLite Select query to pass dynamic values.

Also Read:

  • Solve Python SQLite Exercise
  • Read Python SQLite Tutorial (Complete Guide)

Table of contents

  • Prerequisite
  • Steps to select rows from SQLite table
    • Example to read all rows from SQLite table
  • Use Python variables as parameters in SQLite Select Query
  • Select limited rows from SQLite table using cursor.fetchmany()
  • Select a single row from SQLite table
  • Next Steps:

Prerequisite

Before executing the following program, please make sure you know the SQLite table name and its column details.

For this lesson, I am using the ‘SqliteDb_developers’ table present in my SQLite database.