'Get Employees records below particular month and year(Get based on month and Year)

I have a condition, where I want to get all employees list who are registered below Jan 2022. I want to get employees list who are Active, and who are Inactive till Jan 2022. I want to get based on month and year only. I have tired with my below query but not getting proper results. Any suggestions please.

SELECT A.id,A.first_name,A.status,B.join_date 
FROM employee AS A 
INNER JOIN employee_job_info AS B 
   ON A.id = B.employee_id 
WHERE YEAR(B.join_date)<=2022 AND MONTH(B.join_date)<=1;

Below is my sql fiddle link http://sqlfiddle.com/#!9/e329fc/1



Solution 1:[1]

To be honest, the YEAR()/MONTH() extraction is not necessary. As for the status, I don't see it being a significant condition required here. Nonetheless, I'm concerned that you may aiming for something else here instead of just a simple count. But if you really just want the count, based on your condition, then this query should be enough:

SELECT COUNT(id) as count
FROM employee
WHERE added_on <= '2022-01-31'
  AND last_active_date <= '2022-01-31';

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 FanoFN