My problem is that this query only works if the MainRule table has an ID that matches the Table1 table. I need the query to work even if the MainRule table does not have a matching ID. The records in Table1 should show even if there isn't a matching record(s) in the MainRule table.

Here is my code:

```
SELECT  Person, OrderNum, Name, County, SubmitDate, Days1, 
        SUM(Date_Diff) - 1 AS [Number of Uncleared Days] 
  From
     (SELECT D1.RecordID AS Person, D3.[case no] AS OrderNum, 
             D3.FullName AS Name, D3.County, D3.[SignedDate] AS SubmitDate,
                  DATEDIFF(d, D3.[SignedDate], D3.closedate) AS Days1,
                  DATEDIFF(DAY, [HoldDate],
                  (SELECT TOP 1 [StatusDate]
                     FROM [MainRule] D2
                    WHERE D2.Status = 'Cleared' 
                      AND D1.RecordID = D2.RecordID 
                      AND D1.StatusDate < D2.StatusDate)) AS [Date_Diff]
        FROM [MainRule] AS D1 INNER JOIN table1 AS D3 ON D3.ID = D1.RecordID
       WHERE D1.Status = 'UnCleared') SubQ 
WHERE (SubmitDate BETWEEN '10/01/2017' and '10/17/2017')
GROUP BY Person, OrderNum, Name, County, SubmitDate, Days1

```