I have a table in which the possible value is null, 0, 1 and 3. I have to select only the null and the value equal to 1 in strict order. The query I have is to long. Can you plese help me to make it shorter.
SELECT *
FROM cv_interview_status
WHERE 1
AND (
(`feedback_department` IS NULL)
OR
(
`feedback_department` = 1
AND `contacted_hr` IS NULL
AND `office_interview` IS NULL
AND `department_testing` IS NULL
AND `department_acceptance` IS NULL
AND `add_cv` IS NULL
AND `psychological_test` IS NULL
AND `department_interview` IS NULL
AND `accepted_not_accepted` IS NULL
AND `salary_request_to_ceo` IS NULL
AND `ceo_feedback` IS NULL
AND `salary_offer`IS NULL
AND `accept_salary_offer` IS NULL
AND `hr_documentation` IS NULL
AND `hr_legal_requirements` IS NULL
)
OR
(
`feedback_department` = 1
AND `contacted_hr` =1
AND `office_interview` IS NULL
AND `department_testing` IS NULL
AND `department_acceptance` IS NULL
AND `add_cv` IS NULL
AND `psychological_test` IS NULL
AND `department_interview` IS NULL
AND `accepted_not_accepted` IS NULL
AND `salary_request_to_ceo` IS NULL
AND `ceo_feedback` IS NULL
AND `salary_offer`IS NULL
AND `accept_salary_offer` IS NULL
AND `hr_documentation` IS NULL
AND `hr_legal_requirements` IS NULL
)
OR
(
`feedback_department` = 1
AND `contacted_hr` = 1
AND `office_interview` = 1
AND `department_testing` IS NULL
AND `department_acceptance` IS NULL
AND `add_cv` IS NULL
AND `psychological_test` IS NULL
AND `department_interview` IS NULL
AND `accepted_not_accepted` IS NULL
AND `salary_request_to_ceo` IS NULL
AND `ceo_feedback` IS NULL
AND `salary_offer`IS NULL
AND `accept_salary_offer` IS NULL
AND `hr_documentation` IS NULL
AND `hr_legal_requirements` IS NULL
)
OR
(
`feedback_department` = 1
AND `contacted_hr` =1
AND `office_interview` = 1
AND `department_testing` = 1
AND `department_acceptance` IS NULL
AND `add_cv` IS NULL
AND `psychological_test` IS NULL
AND `department_interview` IS NULL
AND `accepted_not_accepted` IS NULL
AND `salary_request_to_ceo` IS NULL
AND `ceo_feedback` IS NULL
AND `salary_offer`IS NULL
AND `accept_salary_offer` IS NULL
AND `hr_documentation` IS NULL
AND `hr_legal_requirements` IS NULL
)
OR
(
`feedback_department` = 1
AND `contacted_hr` =1
AND `office_interview` = 1
AND `department_testing` = 1
AND `department_acceptance` = 1
AND `add_cv` IS NULL
AND `psychological_test` IS NULL
AND `department_interview` IS NULL
AND `accepted_not_accepted` IS NULL
AND `salary_request_to_ceo` IS NULL
AND `ceo_feedback` IS NULL
AND `salary_offer`IS NULL
AND `accept_salary_offer` IS NULL
AND `hr_documentation` IS NULL
AND `hr_legal_requirements` IS NULL
)
OR
(
`feedback_department` = 1
AND `contacted_hr` =1
AND `office_interview` = 1
AND `department_testing` = 1
AND `department_acceptance` = 1
AND `add_cv` = 1
AND `psychological_test` IS NULL
AND `department_interview` IS NULL
AND `accepted_not_accepted` IS NULL
AND `salary_request_to_ceo` IS NULL
AND `ceo_feedback` IS NULL
AND `salary_offer`IS NULL
AND `accept_salary_offer` IS NULL
AND `hr_documentation` IS NULL
AND `hr_legal_requirements` IS NULL
)
OR
(
`feedback_department` = 1
AND `contacted_hr` =1
AND `office_interview` = 1
AND `department_testing` = 1
AND `department_acceptance` = 1
AND `add_cv` = 1
AND `psychological_test` = 1
AND `department_interview` IS NULL
AND `accepted_not_accepted` IS NULL
AND `salary_request_to_ceo` IS NULL
AND `ceo_feedback` IS NULL
AND `salary_offer`IS NULL
AND `accept_salary_offer` IS NULL
AND `hr_documentation` IS NULL
AND `hr_legal_requirements` IS NULL
)
OR
(
`feedback_department` = 1
AND `contacted_hr` =1
AND `office_interview` = 1
AND `department_testing` = 1
AND `department_acceptance` = 1
AND `add_cv` = 1
AND `psychological_test` = 1
AND `department_interview` = 1
AND `accepted_not_accepted` IS NULL
AND `salary_request_to_ceo` IS NULL
AND `ceo_feedback` IS NULL
AND `salary_offer`IS NULL
AND `accept_salary_offer` IS NULL
AND `hr_documentation` IS NULL
AND `hr_legal_requirements` IS NULL
)
OR
(
`feedback_department` = 1
AND `contacted_hr` =1
AND `office_interview` = 1
AND `department_testing` = 1
AND `department_acceptance` = 1
AND `add_cv` = 1
AND `psychological_test` = 1
AND `department_interview` = 1
AND `accepted_not_accepted` = 1
AND `salary_request_to_ceo` IS NULL
AND `ceo_feedback` IS NULL
AND `salary_offer`IS NULL
AND `accept_salary_offer` IS NULL
AND `hr_documentation` IS NULL
AND `hr_legal_requirements` IS NULL
)
OR
(
`feedback_department` = 1
AND `contacted_hr` =1
AND `office_interview` = 1
AND `department_testing` = 1
AND `department_acceptance` = 1
AND `add_cv` = 1
AND `psychological_test` = 1
AND `department_interview` = 1
AND `accepted_not_accepted` = 1
AND `salary_request_to_ceo` = 1
AND `ceo_feedback` IS NULL
AND `salary_offer`IS NULL
AND `accept_salary_offer` IS NULL
AND `hr_documentation` IS NULL
AND `hr_legal_requirements` IS NULL
)
OR
(
`feedback_department` = 1
AND `contacted_hr` =1
AND `office_interview` = 1
AND `department_testing` = 1
AND `department_acceptance` = 1
AND `add_cv` = 1
AND `psychological_test` = 1
AND `department_interview` = 1
AND `accepted_not_accepted` = 1
AND `salary_request_to_ceo` = 1
AND `ceo_feedback` = 1
AND `salary_offer`IS NULL
AND `accept_salary_offer` IS NULL
AND `hr_documentation` IS NULL
AND `hr_legal_requirements` IS NULL
)
OR
(
`feedback_department` = 1
AND `contacted_hr` =1
AND `office_interview` = 1
AND `department_testing` = 1
AND `department_acceptance` = 1
AND `add_cv` = 1
AND `psychological_test` = 1
AND `department_interview` = 1
AND `accepted_not_accepted` = 1
AND `salary_request_to_ceo` = 1
AND `ceo_feedback` = 1
AND `salary_offer` = 1
AND `accept_salary_offer` IS NULL
AND `hr_documentation` IS NULL
AND `hr_legal_requirements` IS NULL
)
OR
(
`feedback_department` = 1
AND `contacted_hr` =1
AND `office_interview` = 1
AND `department_testing` = 1
AND `department_acceptance` = 1
AND `add_cv` = 1
AND `psychological_test` = 1
AND `department_interview` = 1
AND `accepted_not_accepted` = 1
AND `salary_request_to_ceo` = 1
AND `ceo_feedback` = 1
AND `salary_offer` = 1
AND `accept_salary_offer` = 1
AND `hr_documentation` IS NULL
AND `hr_legal_requirements` IS NULL
)
);
The filter for this table works perfect, but the query is to long, can you give me an advise how can I refactor it?
2
Answers