forked from theyogicoderRI/PythonMadeEasy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunion.py
More file actions
20 lines (15 loc) · 732 Bytes
/
union.py
File metadata and controls
20 lines (15 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import sqlite3
conn = sqlite3.connect('first_db.db')
c = conn.cursor()
# combines all unique values from each table
print("****Union****\n")
for row in c.execute('''SELECT guit_brand, guit_model FROM guitars UNION SELECT e_guit_brand, e_guit_model FROM e_guitars '''):
print(list(row))
print()
print("****Union All****\n")
# combines all values from each table
for row in c.execute('''SELECT guit_brand, guit_model FROM guitars UNION ALL SELECT e_guit_brand, e_guit_model FROM e_guitars '''):
print(list(row))
print("****Union****\n")
for row in c.execute('''SELECT guit_brand, guit_model FROM guitars UNION SELECT e_guit_brand, e_guit_model FROM e_guitars ORDER BY guit_brand '''):
print(list(row))