title: Postgresql Join on Select Statement
body: <p>I want to do a join on a <code>Select</code> Statement in Postgresql, but I am having issues</p>
  
  <pre><code>SELECT 
      s.sessionid, sp.lang 
  FROM 
      sessions s
  INNER JOIN 
      pages sp 
  ON 
      sp.sessionid =  s.sessionid 
  INNER JOIN
  (
      SELECT 
          max(sessionid)
      FROM 
          sessions
      AS 
          maxSession
  )
  ON 
      maxSession = s.sessionid
  WHERE 
      --Where condition
  </code></pre>
  
  <p>I get the following error:
  ERROR:  subquery in FROM must have an alias</p>
  
  <pre><code>LINE 6: (
          ^
  HINT:  For example, FROM (SELECT ...) [AS] foo.
  </code></pre>
  
  <p>If I add the <code>FROM</code></p>
  
  <pre><code>FROM
  (
      SELECT max(sessionid)
      FROM sessions
  )
  AS maxSession
  </code></pre>
  
  <p>I get another error </p>
  
  <pre><code>ERROR:  syntax error at or near "FROM"
  LINE 7:  FROM
  </code></pre>
  
  <p>Ideas?</p>