|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Failing inner joinI am trying to get an overview of non-planned items using the following query:
SELECT dbo.ProjectTasks.TaskId FROM dbo.ProjectTasks INNER JOIN dbo.PlannedItems ON dbo.ProjectTasks.TaskId <> dbo.PlannedItems.TaskId The query should select those records from ProjectTasks which dont have a matching record in the PlannedItems table. This works ok, when you have one or more planneditems and some projecttasks. But if you dont have any planneditems you get an empty result. Anybody know what the problem is with this query? -- Best regards, W.Meints SELECT PT.TaskId
FROM dbo.ProjectTasks PT WHERE NOT EXISTS (SELECT * FROM dbo.PlannedItems WHERE dbo.PlannedItems.TaskId = pt.TaskId) Show quote "W.Meints" <W.Meints@newsgroups.nospam> wrote in message news:193D48B2-C8B3-4937-917C-488B15B1DED3@microsoft.com... >I am trying to get an overview of non-planned items using the following >query: > > SELECT dbo.ProjectTasks.TaskId > FROM dbo.ProjectTasks INNER JOIN > dbo.PlannedItems ON dbo.ProjectTasks.TaskId <> > dbo.PlannedItems.TaskId > > The query should select those records from ProjectTasks which dont have a > matching record in the PlannedItems table. This works ok, when you have > one > or more planneditems and some projecttasks. But if you dont have any > planneditems you get an empty result. > > Anybody know what the problem is with this query? > -- > Best regards, > > W.Meints Thanks for the help Raymond, that worked out great.
-- Show quoteBest regards, W.Meints "Raymond D'Anjou" wrote: > SELECT PT.TaskId > FROM dbo.ProjectTasks PT > WHERE NOT EXISTS (SELECT * FROM dbo.PlannedItems WHERE > dbo.PlannedItems.TaskId = pt.TaskId) > > "W.Meints" <W.Meints@newsgroups.nospam> wrote in message > news:193D48B2-C8B3-4937-917C-488B15B1DED3@microsoft.com... > >I am trying to get an overview of non-planned items using the following > >query: > > > > SELECT dbo.ProjectTasks.TaskId > > FROM dbo.ProjectTasks INNER JOIN > > dbo.PlannedItems ON dbo.ProjectTasks.TaskId <> > > dbo.PlannedItems.TaskId > > > > The query should select those records from ProjectTasks which dont have a > > matching record in the PlannedItems table. This works ok, when you have > > one > > or more planneditems and some projecttasks. But if you dont have any > > planneditems you get an empty result. > > > > Anybody know what the problem is with this query? > > -- > > Best regards, > > > > W.Meints > > > |
|||||||||||||||||||||||