Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If either <code>entry_period_end_date</code> or <code>forecast_period_end</code> is <code>NULL</code>, the row will be returned, even if your other, non-<code>NULL</code> column is not within the period.</p> <p>Probably you meant this:</p> <pre><code>SELECT * FROM Account a LEFT JOIN Entries ef ON ef.account_id = a.account_id AND ( entry_period_end_date BETWEEN … OR forecast_period_end BETWEEN … ) </code></pre> <p>, which will return you all rows with either <code>entry_period_end</code> or <code>forecast_period_end</code> within the given period.</p> <p><strong>Update:</strong></p> <p>A test script:</p> <pre><code>CREATE TABLE account (AccountID INT NOT NULL, AccountName VARCHAR(100) NOT NULL); INSERT INTO account VALUES (1, 'Test'), (2, 'Foobar'), (3, 'Test1'), (4, 'Foobar1'); CREATE TABLE Entries (id INT NOT NULL, AccountID INT NOT NULL, entry_period_end_date DATETIME, forecast_period_end DATETIME, amount FLOAT NOT NULL); INSERT INTO Entries VALUES (1, 1, '2009-12-31', '2009-12-31', 100), (2, 1, NULL, '2009-10-31', 100), (3, 2, NULL, NULL, 100), (4, 3, '2009-10-31', NULL, 100), (5, 4, '2009-10-31', '2009-10-31', 100); SELECT a.*, ef.id FROM Account a LEFT JOIN Entries ef ON ef.accountID = a.accountID AND ( entry_period_end_date BETWEEN '2009-12-01' AND '2009-12-31' OR forecast_period_end BETWEEN '2009-12-01' AND '2009-12-31' ); </code></pre> <p>returns following:</p> <pre><code>1, 'Test', 1 2, 'Foobar', NULL 3, 'Test1', NULL 4, 'Foobar1' NULL </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload