title: Limiting the number of rows in subqueries with Teradata
body: <p>I'm new to Teradata and I'm facing a problem I didn't have with the previous database I used.
  Basically, I'm trying to reduce the number of rows returned in subqueries inside a where clause. I had no problem doing this previously with the ROWNUM function.</p>
  
  <p>My previous query was something like:</p>
  
  <pre><code>SELECT * FROM myTable
  WHERE field1 = 'foo' AND field2 in(
      SELECT field2 FROM anotherTable
      WHERE field3 = 'bar' AND ROWNUM&lt;100);
  </code></pre>
  
  <p>Since I can't use ROWNUM in TD, I've looked for equivalent functions or at least functions that would get me where I wanted even if they were'nt exactly equivalent. 
  I found and tried : ROW_NUMBER, TOP and SAMPLE.</p>
  
  <p>I tried ROW_NUMBER() but Teradata doesn't allow analytic functions in WHERE clauses.
  I tried TOP N but this option is not supported in a subquery.
  I tried SAMPLE N but it is not supported in subqueries either.</p>
  
  <p>So... I have to admit I'm a bit stuck right now and was wondering if there was any solution that would allow me to limit the number of rows returned in a subquery using Teradata and that would be pretty similar to what I did up to now?
  Also, if there aren't any, how would it be possible to build the query differently to use it appropriately with Teradata?</p>
  
  <p>Thanks!</p>