Skip to content

Instantly share code, notes, and snippets.

@Razoxane
Razoxane / reverse_anti-join.sql
Last active July 29, 2016 05:00
Preferred way to suppress reversed journal entries
SELECT je.*
FROM journal_entry AS je ON a.assetID = je.assetID
AND je.reference IN ('OPEN','AQ','DR')
AND CASE WHEN je.reference = 'DR' THEN je.description LIKE 'Direct Reinvestment%' ELSE 1=1 END
AND je.entryType = 'debit'
AND IFNULL(je.assetID,0) > 0
/* some join conditions for the je table, can vary depending on what's being joined (account or asset) */
LEFT JOIN journal_entry AS aj ON je.fundID = aj.fundID
AND je.memberAccountID = aj.memberAccountID