Hi all,
I have 2 tables Objects and ObjectLogs.
Objects Table:-
ObjectID, Name, Description, CreatedDate
1, Delimiter, this is delimiter, 2/26/2013 4:00:00 AM
2, Separater, this is a separater, 2/26/2013 4:00:00 AM
3, Serializer, this is a serializer, 4/26/2013 4:00:00 AM
ObjectsLog table :-
ObjectID, IterationNumber
1, 15
1, 34
1, 45
2, 24
2, 33
3, 56
3, 67
3, 77
I want to delete the records from ObjectsLog table where Objects are of 30 days or more old.
I do it using the following query
DELETE
FROM ObjectsLog
WHERE ObjectID IN (SELECT DISTINCT ObjectID
FROM Objects
WHERE CreatedDate <= GETDATE() - 30)
But this deletes records only with ObjectsID '1'
When I select the older records with the query
SELECT DISTINCT ObjectID
FROM Objects
WHERE CreatedDate <= GETDATE() - 30
it selects both 1 and 2.
But the delete query does not delete records with ObjectID 2.
Is there any problem with the delete query..
Thanks in advance,