I'm having an issue with SQLite in python. The following code doesn't appear to work due to the error
sqlite3.OperationalError: no such column: Company
I'm trying to gather data from both of the tables and display them back to the user using tabulate but cannot proceed and I cannot figure out how to solve this problem. The solution is probably simple but due to my limited programming knowledge I'm unsure how to proceed.
Here's the code:
def view_all_by_CompID(data):
with sqlite3.connect("Clients.db") as db:
cursor = db.cursor()
cursor.execute("""SELECT CompanyID, Forename, Surname, eMail
FROM Clients
JOIN Company
ON Clients.CompanyID = Company.CompanyID
WHERE CompanyID = ?""",(data,))
ViewData = cursor.fetchall()
DataTableCompAndClient([ViewData])
db.commit()
I am unsure why this happens as I'm certain that both tables exist and that (I believe) am calling them correctly. I don't know why it keeps giving me the error so any help would be appreciated. Here's a few details about the code:
Clients.db = The name of the database file
Clients = A table where client information is held
Company = A table where company information is held
CompanyID = A specified Company ID number present in both tables
I've looked at a variety of examples on this site but I can't seem to solve the issue. Any advice would be appreciated.
I have fixed the problem with the help of a friend. There were a few missing lines of code which needed entering, which are the following:
def view_all_by_CompID(data):
with sqlite3.connect("Clients.db") as db:
cursor = db.cursor()
cursor.execute("""SELECT Clients.CompanyID, Clients.Forename, Clients.Surname, Clients.eMail, Company.CompanyID, Company.CompanyName
FROM Clients
INNER JOIN Company
ON Clients.CompanyID = Company.CompanyID
WHERE Clients.CompanyID = ?""",(data,))
ViewData = cursor.fetchall()
DataTableCompAndClient([ViewData])
db.commit()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.