May-06-2019, 02:16 AM
This is a Query I am trying to get right with sqlite3 before I code it into my python program. My SQL is extremely rusty, so It's not obvious to me what I am doing wrong
I have two tables with the same schema, but different data. the schemas are:
So I guess i don't remember how to do this. Di I not need to define all the columns of both tables and only mention the B table after the 'INNER JOIN B ON'?
I have two tables with the same schema, but different data. the schemas are:
Output:sqlite> .schema
CREATE TABLE ElectionResults2012 (VTDDescription, CandidateLName, CandidateFName, CandidateMInit, CandidateSuffix, PartyID, PartyDescription, Town, PoliticalOffice, MachineVotes, AbsenteeVotesTotal, TotalVotes);
CREATE TABLE ElectionResults2014 (VTDDescription, CandidateLName, CandidateFName, CandidateMInit, CandidateSuffix, PartyID, PartyDescription, Town, PoliticalOffice, MachineVotes, AbsenteeVotesTotal, TotalVotes);
my test query is:Output:sqlite> SELECT
...> A.VTDDescription, B.VTDDescription, A.CandidateLName, B.CandidateLName, A.CandidateFName, B.CandidateFName,
...> A.CandidateMInit, B.CandidateMInit, A.CandidateSuffix, B.CandidateSuffix, A.PartyID, B.PartyID, A.PartyDescription,
...> A.Town, B.Town, A.PoliticalOffice, B.PoliticalOffice, A.MachineVotes, B.MachineVotes, A.AbsenteeVotesTotal,
...> B.AbsenteeVotesTotal, A.TotalVotes, B.TotalVotes
...> FROM
...> ElectionResults2012 A, ElectionResults2014 B
...> INNER JOIN B ON
...> B.VTDDescription = A.ElectionResults2012.VTDDescription
...> and
...> A.ElectionResults2014.PoliticalOffice = B.ElectionResults2012.PoliticalOffice
...> ORDER BY
...> ElectionResults2012.Town;
I get the following error: Error: no such table: B
So I guess i don't remember how to do this. Di I not need to define all the columns of both tables and only mention the B table after the 'INNER JOIN B ON'?