title: Nested Inner join query
body: <p>I have four tables called attr, data, extradata and syst. I have to do multiple/nested inner joins to get some attributes from all 4 tables, and running into issues because of that. For some background, there is a column called 'ID' in 'data' table that I am obtaining by an inner join between data and extradata as follows:</p>
  
  <pre><code>Select X.ID FROM data X 
  INNER JOIN extradata XA 
  ON X.dataID = XA.dataID 
  WHERE X.data = 'condition1' and NOT XA.additionaldata = 'condition2'
  </code></pre>
  
  <p>This ID has to be matched with the ID in attr table, and one more INNER join with syst table. The following is a very abbreviated version of the query that's I'm currently trying out:</p>
  
  <pre><code>SELECT TOP(10) a.ID 
  FROM attr AS a 
  INNER JOIN data AS X ON a.ID = 
  (
      Select X.ID FROM data X 
      INNER JOIN extradata XA 
      ON X.dataID = XA.dataID 
      WHERE X.data = 'condition1' and NOT XA.additionaldata = 'condition2'
  )
  INNER JOIN syst AS s ON a.sysID = s.sysID
  WHERE s.desc = 'condition3'
  </code></pre>
  
  <p>There is something (obviously) wrong with my query, so I'd be grateful for any suggestions. Thanks in advance!</p>