title: Web2Py DAL, left join and operator precedence
body: <p>In my DB, I've basically 3 tables:</p>
  
  <ol>
  <li>usergroup(id, name, deleted)</li>
  <li>usergroup_presentation(id, groupid, presentationid)</li>
  <li>presentation(id, name)</li>
  </ol>
  
  <p>I'm trying to run this DAL query:</p>
  
  <pre><code>left_join = db.usergroup_presentation.on((db.usergroup_presentation.group_id==db.usergroup.id)
  &amp;(db.usergroup_presentation.presentation_id==db.presentation.id))
  result = db(db.usergroup.deleted==False).select(
         db.usergroup.id, 
         db.usergroup.name, 
         db.usergroup_presentation.id, 
         left=left_join, 
         orderby=db.usergroup.name)
  </code></pre>
  
  <p>And SQL returns this errors: <code>Unknown column 'presentation.id' in 'on clause'</code></p>
  
  <p>The generated SQL looks something like that:</p>
  
  <pre><code>SELECT  usergroup.id, usergroup.name, usergroup_presentation.id 
  FROM presentation, usergroup
  LEFT JOIN usergroup_presentation ON ((usergroup_presentation.group_id = usergroup.id) AND (usergroup_presentation.presentation_id = presentation.id)) 
  WHERE (usergroup.deleted = 'F')
  ORDER BY usergroup.name;
  </code></pre>
  
  <p>I did some researches on Google and I got this:
  <a href="http://mysqljoin.com/joins/joins-in-mysql-5-1054-unknown-column-in-on-clause/" rel="nofollow">http://mysqljoin.com/joins/joins-in-mysql-5-1054-unknown-column-in-on-clause/</a></p>
  
  <p>Then I tried to run this query directly in my DB:</p>
  
  <pre><code>SELECT  usergroup.id, usergroup.name, usergroup_presentation.id 
  FROM (presentation, usergroup)
  LEFT JOIN usergroup_presentation ON ((usergroup_presentation.group_id = usergroup.id) AND (usergroup_presentation.presentation_id = presentation.id)) 
  WHERE (usergroup.deleted = 'F')
  ORDER BY usergroup.name;
  </code></pre>
  
  <p>And indeed it works when adding the brackets around the <code>FROM</code> tables.</p>
  
  <p>My question is how can I generate a SQL query like this (with brackets) with DAL without executing a basic <code>executesql</code> ?</p>
  
  <p>Even better, I would like to get a cleaner SQL query using <code>INNER JOIN</code> and <code>LEFT JOIN</code>. I don't know if it's possible with my query though.</p>