Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 joins - help please

Author  Topic 

bpsintl
Posting Yak Master

132 Posts

Posted - 2009-04-02 : 03:50:49
I have 2 tables, invoices and income.

Invoices Table
ID
total

Income Table
income_id
invoiceid
amount

There are more fields in each table but they are the ones relating to my query.

Basically, my system creates a row in the income table each time an invoice is created, so that we can reconcile it with the bank when the bank statement comes.

My problem is that I found some instances when these income rows were not created.

I would like to query those tables and bring back all invoice records that do not have a corresponding income row on invoices.id = income.invoiceid

I've tried left and right joins but dont think I'm getting it right.

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2009-04-02 : 07:30:42
select *
from invoices iv left join income ic
on iv.id = ic.invoiceid
where ic.income_id is null

Em
Go to Top of Page

bpsintl
Posting Yak Master

132 Posts

Posted - 2009-04-02 : 07:38:49
Cheers Em, thats the ticket!!
Go to Top of Page
   

- Advertisement -