Hopefully the title isn't too vague, but I'll explain. I'm pretty new to advanced queries so unfortunately this is not as much of a "i'm trying this" as much as a "how would I even go about doing this" type of question.
I have a table of user activity. When they do something on the site, it gets entered into this database. Unfortunately there was a change in how logging-in was tracked. So now I need to find all records for each user id, check the date for each record and see if there is a record with a specific id for that date.
I realize that sounds confusing so I will break it down into the best programming logic I can
- get list of records for user_id order by date
- for each date, check if id 5 exists
- if id 5 doesn't exist, tell me about
Basically I will be inserting that id into the table where that id doesn't exist based on that date.
Any help would be greatly appreciated. Thanks in advance.
Edit**I forgot to add a basic structure here.
id | user_id | item_id | stamp------------------------------------------------------1 | user1 | 1 | 2012-08-252 | user1 | 2 | 2012-08-253 | user1 | 3 | 2012-08-254 | user1 | 4 | 2012-08-255 | user1 | 6 | 2012-08-256 | user1 | 7 | 2012-08-257 | user1 | 5 | 2012-08-268 | user1 | 11 | 2012-08-269 | user1 | 13 | 2012-08-26
So that's the basic structure. User1 is missing id 5 on 2012-08-25
so I would need to add it in with that date. user1 is not missing id 5 on 2012-08-26
so I would not need to insert anything at all. Does that clear anything up?