Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with complex query

Status
Not open for further replies.

JMay0816

Programmer
Mar 1, 2007
34
US
I'm a little baffled on this one. Here's what I have: 2 tables which both share several common fields. I'm only dealing with two. It's a one to many relationship (only one record in table1, as opposed to possible many in table2)

Snapshot of data:
Table1

RecNum ------- Item
2009001 1
2009001 2
2009002 1
2009003 1
2009003 2
2009003 3

Table2
RecNum ------- Item
2008001 2
2009001 2
2009003 1
2009003 1
2009003 1
2009003 2
2009003 3

(Select recnum, item from Table2 where recnum like '2009%' group by recnum, item)

Tabel2 Query Results

2009001 2
2009003 1
2009003 2
2009003 3

I'm looking to return only those records from Table1 that do not have a corresponding recordset in Table2.

So my output should be from Table1:

RecNum ------- Item
2009001 1
2009002 1

I've tried using JOIN (Select....
but it keeps telling me I'm missing a keyword so obviously not coding it correctly.

Can someone lend some assistance?

Thanks greatly!
 
TRy

Select t1.recnum, t1.item
from Table1 t1
left outer join table2
on t1.recnum = t2.recnum and t1.item = t2.item
where t1.recnum like '2009%'
and t2.recnum is null
group by t1.recnum, t1.item

Ian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top