title: Select records from master table based on condition from 4th detail table
body: <p>I have 4 tables: Table1, Table2, Table3, Table4 each one is a detail the prior one for example table4 is a detail for table3 and so on. here is my schema:</p>
  
  <p>Table1:</p>
  
  <pre><code>PK1 Integer,
  Name1 varchar(15),...
  </code></pre>
  
  <p>Table2:</p>
  
  <pre><code>PK2 Integer,
  PK1 Integer, -- This is foreign key to Table1.PK1
  Name2 varchar(15),...
  </code></pre>
  
  <p>Table3: </p>
  
  <pre><code>PK3 Integer,
  PK2 Integer, -- This is foreign key to Table2.PK2
  Name3 varchar(15),...
  </code></pre>
  
  <p>Table4: </p>
  
  <pre><code>PK4 Integer,
  PK3 Integer, -- This is foreign key to Table3.PK3
  Name4 varchar(15),...
  </code></pre>
  
  <p>I need now to select records from Table1 based on certain value from Table4 for example when Table4.PK4 = 3.</p>
  
  <p>So I tried like that:</p>
  
  <pre><code>Select * from table1 where PK1 in (
    select PK1 from Table2 where PK2 in (
    select PK2 from Table3 where PK3 in (
    select PK3 from Table4 where PK4 = 3
  )))
  </code></pre>
  
  <p>I got correct results but is it the best/optimized way or there is better SQL I should use ?</p>