title: Translate SQL query into a well made QuerySet
body: <p>I have a raw queryset that i want to translate in QuerySet. But i always ends up with error.</p>
  
  <p>Here is the raw query :</p>
  
  <pre><code>q = Table1.objects.raw(
       '''SELECT base_table1.id, base_table1.name, base_table1.n_id, count(base_table2.id) as 'count', max(base_table2.timestamp) as 'latest'
                                       FROM base_table1
                                       INNER JOIN base_table3 on base_table3.table1_id = base_table1.id
                                       INNER JOIN base_table2 on base_table2.table3_id = base_table3.id
                                       GROUP by base_table1.id'''
  </code></pre>
  
  <p>Note : here i don't need the base_table1.id, but it was required for the rawQuerySet</p>
  
  <p>Here are the models :</p>
  
  <pre><code>class Table1(models.Model):
  n_id = models.PositiveIntegerField()
  name = models.CharField(max_length=45)
  
  class Table2(models.Model):
  table3 = models.ForeignKey(
      Table3, null=True, blank=True, on_delete=models.SET_NULL
  )
  timestamp = models.DateTimeField(null=True)
  
  
  class Table3(models.Model):
  table1 = models.ForeignKey(
      Table1, null=True, related_name='t_entries', on_delete=models.SET_NULL
  )
  </code></pre>
  
  <p>Great thanks in advance for your answers.</p>