Get rows from both tables
Posted on 2012-03-29
I am using the below query to get results from my primary table [GLJrnDtl]
I have a join to another table and all results are coming in great. The problem I'm just not understanding is that I need results from BOTH tables actually. There are certain records in [InvcHed] that ARE NOT contained within [GLJrnDtl] yet I DO need all records from [GLJrnDtl].
So basically, I need to know how to show results from both tables.
SELECT GLJrnDtl.FiscalYear, GLJrnDtl.FiscalPeriod, GLJrnDtl.PostedBy, GLJrnDtl.JournalNum, GLJrnDtl.JournalLine, GLJrnDtl.Description, GLJrnDtl.ARInvoiceNum,
GLJrnDtl.SegValue1, GLJrnDtl.SegValue2, GLJrnDtl.JournalCode, GLJrnDtl.DebitAmount, GLJrnDtl.CreditAmount, InvcHead.InvoiceNum
FROM GLJrnDtl WITH (NOLOCK) LEFT OUTER JOIN
InvcHead ON GLJrnDtl.ARInvoiceNum = InvcHead.InvoiceNum
WHERE (GLJrnDtl.FiscalYear = '2012') AND (GLJrnDtl.FiscalPeriod = '2') AND (GLJrnDtl.SegValue1 BETWEEN '400000' AND '499999')
ORDER BY GLJrnDtl.JournalCode