Hi,
I'm currently trying to write a query that will return all users that have not logged time for a given date in our timesheet system. We currently have 2 tables, timesheets and users. I am trying to make a query that will return a list of users that do not have an entry in the timesheets table for a date range. There is only one record in the timesheets table per-day, this should be simple but I can't figure out how to approach this for the life of me.
Any help would be appreciated :).
+-----------------------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------------------+------------------+------+-----+---------+----------------+ | timesheetID | int(11) unsigned | NO | PRI | NULL | auto_increment | | timesheetForUser | int(11) unsigned | NO | | | | | timesheetForDate | date | NO | | | | | timesheetForCheckIn | int(11) | YES | | NULL | | | timesheetNotes | text | YES | | NULL | | | timesheetIsFilled | tinyint(1) | NO | | | | | timesheetNoFillReason | int(11) unsigned | NO | | | | | timesheetCreatedOn | datetime | NO | | | | | timesheetCreatedBy | int(11) unsigned | NO | | | | | timesheetUpdatedOn | datetime | YES | | NULL | | | timesheetUpdatedBy | int(11) unsigned | YES | | NULL | | +-----------------------+------------------+------+-----+---------+----------------+
+--------------------------------+---------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------------------------------+---------------+------+-----+---------+----------------+ | userID | int(11) | NO | PRI | NULL | auto_increment | | userAccount | int(11) | YES | | NULL | | | userOrganization | int(11) | YES | | NULL | | | userIsEmployee | tinyint(4) | YES | | 0 | | | userEmployeeSince | date | YES | | NULL | | | userName | varchar(255) | YES | | NULL | | | userTitle | varchar(255) | YES | | NULL | | | userEmail | varchar(255) | YES | | NULL | | | userLogin | varchar(50) | YES | | NULL | | | userPassword | varchar(255) | YES | | NULL | | | userSendInvitation | tinyint(4) | YES | | NULL | | | userAddress1 | varchar(255) | YES | | NULL | | | userAddress2 | varchar(255) | YES | | NULL | | | userCity | varchar(255) | YES | | NULL | | | userCountry | char(2) | YES | | NULL | | | userState | varchar(6) | YES | | NULL | | | userStateOther | varchar(255) | YES | | NULL | | | userZip | varchar(20) | YES | | NULL | | | userPhone | varchar(50) | YES | | NULL | | | user_easypaycode | varchar(6) | YES | | NULL | | | userFax | varchar(50) | YES | | NULL | | | userCell | varchar(50) | YES | | NULL | | | userTimezone | int(11) | YES | | NULL | | | userNotes | text | YES | | NULL | | | userActive | tinyint(4) | NO | | 0 | | | userDisplayPictureType | tinyint(4) | YES | | NULL | | | userDisplayPicture | varchar(255) | YES | | NULL | | | userThumbnailPicture | varchar(255) | YES | | NULL | | | userCanWriteMessages | tinyint(4) | NO | | 0 | | | userCanWriteComments | tinyint(4) | NO | | 0 | | | userCanUploadFiles | tinyint(4) | NO | | 0 | | | userCanCreateEvents | tinyint(4) | NO | | 0 | | | userCanCreateTickets | tinyint(4) | NO | | 0 | | | userCanManageProjects | tinyint(4) | NO | | 0 | | | userCanManageUsers | tinyint(4) | NO | | 0 | | | userCanManageOrganizations | tinyint(4) | NO | | 0 | | | userCanManageUserGroups | tinyint(4) | NO | | 0 | | | userCanManageMessageCategories | tinyint(4) | NO | | 0 | | | userCanManageSetupOptions | tinyint(4) | NO | | 0 | | | userCanManageAllUsersItems | tinyint(4) | NO | | 0 | | | userCanEnterTimesheets | tinyint(4) | NO | | | | | userCanManageTimesheets | tinyint(4) | NO | | | | | userCanUseTimeclock | tinyint(4) | YES | | NULL | | | userCanOnlyUseTimeclock | tinyint(4) | YES | | NULL | | | userLastLogin | datetime | NO | | | | | userPWResetText | varchar(255) | YES | | NULL | | | userDeleted | tinyint(4) | NO | | 0 | | | userDeletedBy | int(11) | YES | | NULL | | | userDeletedOn | datetime | YES | | NULL | | | userMinHoursPerDay | decimal(10,1) | YES | | NULL | | +--------------------------------+---------------+------+-----+---------+----------------+
In addition there is no record created in timesheets if there is no time logged for a day.