title: Geeting results from multipe(4) tables joins using SQL or code if needed (python)
body: <p>I'm working with PostgreSQL 10 and Python 3. I know how to o simple selects or joins, buy I have issues when need to combine 4 tables related 2 by 2.</p>
  
  <p>I mention, that I use Phyton, in case is necessary to combine queries using code.</p>
  
  <p>I have the following tables: Company, CompanyLogo, Product, ProductImage, with the following</p>
  
  <ol>
  <li><p>Relations:</p>
  
  <ul>
  <li>Company Logo O1O with Company</li>
  <li>Product has FK to Company</li>
  <li>ProductImage FK with Product</li>
  </ul></li>
  <li><p>Structure</p>
  
  <pre><code>Company
  
  Id  | slug
   1     1
  </code></pre></li>
  </ol>
  
  <hr>
  
  <pre><code>    Logo
      Id | path | company_id
      1     url        1
  
  
     -----------
      Product
      Id | company_id
      1     1
      2     1
  
  
      ProductImage
  
      Id | path | product_id
      1     url   1
      2     url   1 
      3     url   1
  </code></pre>
  
  <p>I need: </p>
  
  <ol>
  <li><p>Get list of all companies, and for each company get:</p>
  
  <ul>
  <li>the company slug</li>
  <li>the logo</li>
  <li>up to 3 products and their first image</li>
  </ul></li>
  <li><p>Get one company based on id and:</p>
  
  <ul>
  <li>the company slug</li>
  <li>the logo</li>
  <li>all product and their first image</li>
  </ul></li>
  </ol>