SQLite table JOIN in pandas (Python)

SQLite table JOIN queries can be implemented in Python with sqlite3 and (optionally) with pandas. Below example joins client and client order data by client ID.

import pandas as pd
import sqlite3

# connect to database
con = sqlite3.connect('sales.db')

# write query
query = '''
SELECT *
FROM orders
JOIN clients
ON orders.customer_id = clients.customer_id
'''

# execute query in Python using pandas (obtaining results in DataFrame format)
df = pd.read_sql_query(query, conn)

Close

Meta