Query All Records

Date: March 14th 2016
Last updated: March 14th 2016

This example uses an existing database and record entries already created.

import sqlite3

# connect
con = sqlite3.connect('gitbook.db')

# cursor
cur = con.cursor()

# execute 
cur.execute('SELECT * FROM vet_visit \
             INNER JOIN animals \
             ON \
                 animals.animalid == vet_visit.visitanimalid \
                 \
             INNER JOIN patient \
             ON \
                 patient.patientid == vet_visit.visitpatientid;')

rows = cur.fetchall()
for row in rows:
    print(row)

# commit and close
con.commit()
con.close()

Output

(1, 1, 1, 35.0, '2016-03-13 01:19:33', 1, 'dog', 1, 'rover', 1)
(2, 1, 1, 35.0, '2016-03-13 01:19:33', 1, 'dog', 1, 'rover', 1)
(3, 2, 2, 43.0, '2016-03-13 01:19:33', 2, 'cat', 2, 'tinkles', 2)
(4, 1, 1, 126.0, '2016-03-13 01:19:33', 1, 'dog', 1, 'rover', 1)
(5, 2, 2, 43.0, '2016-03-13 01:19:33', 2, 'cat', 2, 'tinkles', 2)
(6, 3, 1, 35.0, '2016-03-13 02:11:06', 1, 'dog', 3, 'peanut', 1)
(7, 3, 1, 385.0, '2016-03-13 02:11:06', 1, 'dog', 3, 'peanut', 1)
(8, 3, 1, 13.0, '2016-03-13 02:11:06', 1, 'dog', 3, 'peanut', 1)
(9, 1, 1, 35.0, '2016-03-13 02:11:06', 1, 'dog', 1, 'rover', 1)
(10, 3, 1, 73.0, '2016-03-13 02:11:06', 1, 'dog', 3, 'peanut', 1)
(11, 4, 1, 10.0, '2016-03-13 02:16:50', 1, 'dog', 4, 'pickles', 6)
(12, 5, 1, 15.0, '2016-03-13 02:16:50', 1, 'dog', 5, 'snoopy', 1)
(13, 4, 1, 24.0, '2016-03-13 02:16:50', 1, 'dog', 4, 'pickles', 6)
(14, 5, 1, 23.0, '2016-03-13 02:16:50', 1, 'dog', 5, 'snoopy', 1)
(15, 4, 1, 10.0, '2016-03-13 02:17:31', 1, 'dog', 4, 'pickles', 6)
(16, 5, 1, 15.0, '2016-03-13 02:17:31', 1, 'dog', 5, 'snoopy', 1)
(17, 4, 1, 24.0, '2016-03-13 02:17:31', 1, 'dog', 4, 'pickles', 6)
(18, 5, 1, 23.0, '2016-03-13 02:17:31', 1, 'dog', 5, 'snoopy', 1)

results matching ""

    No results matching ""