mercredi 6 mai 2015

SQLite INNER JOIN in python: sqlite3.OperationalError: no such column:

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 Company ID, 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.

Aucun commentaire:

Enregistrer un commentaire