Off topic SQL question - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Forum & Off Topic (https://python-forum.io/forum-23.html) +--- Forum: Bar (https://python-forum.io/forum-27.html) +--- Thread: Off topic SQL question (/thread-18104.html) |
Off topic SQL question - Larz60+ - May-06-2019 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: my test query is: 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'? RE: Off topic SQL question - Larz60+ - May-06-2019 This is what I wanted, don't even know why I thought I needed a join:
RE: Off topic SQL question - nilamo - May-08-2019 Without a join specified, it'd be a full outer join, which is sort of a worst case scenario (every row of one table matched with every row of the other table). I've actually never seen the syntax from table_1, table_2 before, and I didn't know that'd work. I would have written it like this:FROM ElectionResults2012 A JOIN ElectionResults2014 B ON B.VTDDescription = A.VTDDescription AND A.PoliticalOffice = B.PoliticalOfficeAlso, I don't see why these are two different tables. They're the same, separated only by year, so I'd just have one table, with an extra column for which ElectionPeriod the results represent. But that's just a nitpick :p RE: Off topic SQL question - Larz60+ - May-08-2019 The entire database is being reorganized and normalized, but I still need to be able to access whats there, so your response is both helpful and appreciated. |