SELECT Queries
Python Code Template
# Python + SQLite Lesson 1
# Step 1: import SQLite3 Module
import sqlite3
# Step 2: create a connection with a SQL database file
connection = sqlite3.connect("pokemon.db")
# Step 3: create a cursor that helps us to communicate with a the database
cursor = connection.cursor()
# Step 4: execute SQL queries with a method called ".execute()" from the cursor
# QUERIES GO HERE
# Step 5: when finished with the database, close your cursor and connection
cursor.close()
connection.close()This Tutorial's Database: pokemon.db
pokemon.dbname
pkmn_type1
pkmn_type2
number
Database Explained
SELECT Query
SELECT QueryGet all data from a table
name
pkmn_type1
pkmn_type2
number
Python Code
Python Output:
Understanding .fetchall()
.fetchall()Get data from a single column
name
Python Code
Python Output:
Selecting multiple columns
number
name
Python Output:
Exercises
Connected Reading
Last updated