title: Sub-Queries in Netezza
body: <p>I am trying to port a SQL from Oracle 11 G to Netezza. </p>
  
  <p>Here is my query in Oracle:</p>
  
  <pre><code>SELECT
      ID, TEACHERID, CLASS, SECTION, MAJOR, SUPERVISOR, COURSE, SCORE, SCOREDATE, 
      (select SCORE from STUDENT_SCORES d2 where d2.ID=d1.ID and d2.SCOREDATE (d1.SCOREDATE)-28 and d1.COURSE=d2.COURSE)  as PRIORSCORE, 
      (d1.SCOREDATE)-28 as PRIORSCOREDT,
      REMCD
  FROM 
      STUDENT_SCORES d1
  WHERE 
      TEACHERID='T1' AND SCOREDATE=(SELECT MAX(SCOREDATE) FROM STUDENT_SCORES WHERE TEACHERID='T1')
  </code></pre>
  
  <p>When I run this in Netezza I get an error:</p>
  
  <pre><code>ERROR:  (2) This form of correlated query is not supported - consider rewriting
  </code></pre>
  
  <p>How do I rewrite this query for Netezza? Please help.</p>