title: SQL Query Performance Issue sub-query and missing parenthesis
body: <p>I have two Questions in the below query </p>
  
  <ol>
  <li><p>When i tried running the query I am getting the below error in oracle</p></li>
  <li><p>Performance issue i.e when i run the query without the IN clause i.e remove the {select * from cand_profile where postal_code in } in the below query it is taking 15 sec .How to fine tune this sql query ?</p></li>
  </ol>
  
  <p>Query</p>
  
  <pre><code>select *
  from cand_profile 
  where postal_code in (
      SELECT ZIP
      FROM (
          SELECT
              dest.ID,
              dest.postal_code AS ZIP,
              ACOS(SIN(RADIANS(src.latitude))*SIN(RADIANS(dest.latitude))+COS(RADIANS(src.latitude))*COS(RADIANS(dest.latitude))*COS(RADIANS(src.longitude)-RADIANS(dest.longitude)))* 3959 AS DISTANCE
          FROM post_codes dest
              CROSS JOIN
          post_codes src
          WHERE src.ID = (
              SELECT ID
              FROM post_codes
              WHERE postal_code = '60195'
              GROUP BY ID
          ) 
          AND ( dest.ID &lt;&gt; src.ID OR  dest.ID = src.ID )
      )
      GROUP BY ID,ZIP,DISTANCE
      HAVING DISTANCE &lt;= 5
      ORDER BY DISTANCE
  ))
  </code></pre>
  
  <blockquote>
    <p>ORA-00907: missing right parenthesis
    00907. 00000 -  "missing right parenthesis"
    *Cause:<br>
    *Action:</p>
  </blockquote>