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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LEFT OUTER JOIN to same table?

Status
Not open for further replies.

Waynest

Programmer
Joined
Jun 22, 2000
Messages
321
Location
GB
Hi

This is driving me nuts. I have a table which contains production plans. Several plans are held in the same table, each referenced by the 'Seq' field. What I am trying to determine is which records have been added to plan 17 which did not exist in plan 16. I've used a LEFT OUTER join but cant get it to work (0 rows returned although I've deleted a record from plan 16 which is otherwise identical to 17). The only thing I've done differently here to other queries I've written is create a join to the SAME TABLE.

Here's the query:

SELECT K1.* FROM KnitPlanWeek K1
LEFT OUTER JOIN KnitPlanWeek K2 ON K1.Style = K2.Style AND K1.Size = K2.Size AND K1.Year = K2.Year AND K1.Month = K2.Month AND K1.Week = K2.Week
WHERE K1.Seq = 17 AND K2.Seq = 16
AND ((K2.Style IS NULL)
OR (K2.Size IS NULL)
OR (K2.Year IS NULL)
OR (K2.Month IS NULL)
OR (K2.Week IS NULL))

I'm running this in SQL Server version 7 using Query Analyzer. Help!

Wayne
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top