title: How to join data from two tables in SQLAlchemy?
body: <p>I have 3 tables: <code>Account</code>, <code>User</code> and <code>Organization</code>.</p>
  
  <ul>
  <li><code>Account</code> consists of <code>id</code>, <code>name</code> and <code>organization_id</code>.</li>
  <li><code>User</code> consists of <code>email</code> and <code>organization_id</code>.</li>
  <li><code>Organization</code> consists of <code>id</code> and <code>name</code>.</li>
  </ul>
  
  <p>Each <code>Account</code> is registered to an <code>Organization</code>(through <code>organization_id</code>) and each <code>User</code> is registered to an <code>Organization</code>. The challenge is to display all the emails (from <code>User</code>) to the <code>Account</code> corresponding to the <code>name</code> whose <code>organization_id</code> matches the <code>organization_id</code> of <code>User</code>.</p>
  
  <p>Here's my code till now:</p>
  
  <pre><code>class Account(db.Model):
      __tablename__ = "account"
      id = Column(Integer, primary_key=True)
      name = Column(String(50), index=True, unique=True)
      organization = Column(Integer, 
          ForeignKey("organization.id"),nullable=False, index=True)
  
  class User(UserMixin, db.Model, RBACUserMixin):
      __tablename__ = "user"
      id = db.Column(db.Integer, primary_key=True)
      email = db.Column(db.String(255), unique=True)
      organization = Column(Integer, ForeignKey("organization.id"), 
                        nullable=False, index=True)
  
  class Organization(db.Model):
      __tablename__ = "organization"
      id = Column(Integer, primary_key=True)
      name = Column(String(512))
      users = relationship("User", backref="organizations")
      accounts = relationship("Account", backref="organizations")
  </code></pre>