title: Joining 2 Tables on Multiple Non Foreign Key Columns in Flask with SQLAlchemy and Retrieving All Columns
body: <p>I have a few tables shown below that I would like to join on columns that are not foreign keys to each other's tables and then have access to the columns of both. Here are the classes:</p>
  
  <pre><code>class Yi(db.Model):
  
      year = db.Column(db.Integer(4), primary_key=True)
      industry_id = db.Column(db.String(5), primary_key=True)
      wage = db.Column(db.Float())
      complexity = db.Column(db.Float())
  
  class Ygi(db.Model, AutoSerialize):
  
      year = db.Column(db.Integer(4), primary_key=True)
      geo_id = db.Column(db.String(8), primary_key=True)
      industry_id = db.Column(db.String(5), primary_key=True)
      wage = db.Column(db.Float())
  </code></pre>
  
  <p>So, what I would like to get are the columns of both tables joined by the IDs I specify, in this case Year and industry_id. Is this possible? Here is the SQL I've written to achieve this...</p>
  
  <pre><code>SELECT 
      yi.complexity, ygi.* 
  FROM
      yi, ygi 
  WHERE 
      yi.year = ygi.year and 
      yi.industry_id = ygi.industry_id
  </code></pre>