I have a table that stores all data that a user answers. I am trying to find out which user_id’s have not updated anything in the system since Jan 1, 2012.
Each user will have about 500 item_id’s in the database. The query I am trying to process will return the DISTINCT user_id of every user that has not updated their data since a given year. Not all item_id’s have to be updated so if any item_id has a dt greater than the datetime I am trying to find then I need to ignore them, even if it’s 1 record. I only want user_id’s that have not updated a single field since 2012.
Any help or push in the right direction is appreciated.
Thanks!
The table
CREATE TABLE IF NOT EXISTS `item_results` (
`item_id` int(11) NOT NULL DEFAULT '0',
`user_id` int(11) NOT NULL DEFAULT '0',
`result` text NOT NULL,
`specifier` text NOT NULL,
`dt` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
UNIQUE KEY `item_id` (`item_id`,`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
You need to create a subquery that gets their latest
dtvalue (MAX VALUE) like this one below (it works if you want to get all the columns of the last update of the user.)or simply (the one you are looking for.)
Hope this helps.