Did you think of removing log_type != 'Stafflog' here? if you need records for log_type = 'editaccnt', you don't need to add log_type != 'X' condition to this query. Rest of the query looks ok.