title: Speed Up SQL Query Performance
body: <p>I have the following SQL Query:  </p>
  
  <pre><code>SELECT * FROM (
        SELECT dbo.Table1.Table1_ID, dbo.Table1.Name, dbo.Table5.Ergebniss, 
        dbo.Table2.Datum, dbo.Table3.Stelle, dbo.Table2.Nummer 
      FROM dbo.Table1 
      INNER JOIN dbo.Table2 ON dbo.Table1.Table1_ID = dbo.Table2.Table1_ID 
      INNER JOIN dbo.Table3 ON dbo.Table2.Table2_ID = dbo.Table3.Table2_ID 
      INNER JOIN dbo.Table4 ON dbo.Table3.Table3_ID = dbo.Table4.Table3_ID 
      INNER JOIN dbo.Table5 ON dbo.Table4.Table4_ID = dbo.Table5.Table4_ID
      GROUP BY dbo.Table1.Table1_ID, dbo.Table1.Name, dbo.Table5.Wert2, 
      dbo.Table5.Wert1, dbo.Table5.Ergebniss, dbo.Table2.Datum, 
      dbo.Table2.Nummer, dbo.Table3.Stelle
         HAVING (dbo.Table1.Table1_ID = 1) 
           AND (dbo.Table2.Nummer = (SELECT MAX(dbo.Table2.Nummer) AS 
     MaxSchichtNummer 
   FROM dbo.Table1 
   INNER JOIN dbo.Table2 ON dbo.Table1.Table1_ID = dbo.Table2.Table1_ID 
   WHERE (dbo.Table1.Table1_ID = 1))) ) AS TG 
   where tg.Nummer 
     in (Select top 5000 Nummer from dbo.Table2 where Table1_ID=1 order by datum 
   desc) order by Datum desc
  </code></pre>
  
  <p>It takes a very long time so select the data. Is it possible to speed up the query?</p>