title: SQL - table alias scope
body: <p>I've just learned ( yesterday ) to use "exists" instead of "in".</p>
  
  <pre><code> BAD
   select * from table where nameid in ( 
            select nameid from othertable where otherdesc =  'SomeDesc' )      
   GOOD
   select * from table t where exists ( 
            select nameid from othertable o where t.nameid = o.nameid and otherdesc =  'SomeDesc' )      
  </code></pre>
  
  <p>And I have some questions about this:</p>
  
  <p>1) The explanation as I understood was: <em>"The reason why this is better is because only the matching values  will be returned instead of building a massive list of possible results"</em>.  Does that mean that while the first subquery might return 900 results the second will return only 1 ( yes or no )?</p>
  
  <p>2) In the past I have had the RDBMS complainin: "only the first 1000 rows might be retrieved", this second approach would solve that problem?</p>
  
  <p>3) What is the scope of the alias in the second subquery?... does the alias only lives in the parenthesis? </p>
  
  <p>for example </p>
  
  <pre><code> select * from table t where exists ( 
            select nameid from othertable o where t.nameid = o.nameid and otherdesc =  'SomeDesc' )      
   AND 
            select nameid from othertable o where t.nameid = o.nameid and otherdesc =  'SomeOtherDesc' )      
  </code></pre>
  
  <p>That is, if I use the same alias ( o for table othertable ) In the second "exist" will it present any problem with the first exists? or are they totally independent?</p>
  
  <p>Is this something Oracle only related or it is valid for most RDBMS?</p>
  
  <p>Thanks a lot</p>