Say I have a table like this:
model_id | object_id | date_modified
1 | 123 | NULL
1 | 123 | 2012-12-11 16:55:21
1 | 456 | 2012-12-11 16:52:21
1 | 789 | NULL
I want to return the object_ids that have not been modified. Here’s what I’ve tried thus far:
SELECT object_id from Table WHERE date_modified IS NULL
This returns 123 and 789, I only want 789.
SELECT DISTINCT object_id from Table WHERE date_modified IS NULL
This also returns 123 and 789 as the DISTINCT clause is applied after the WHERE filters the results.
Is there a way to achieve this with a single query or should I just return a list of distinct object_ids and loop through and filter programmatically?
1 Answer