Danvin Lee Qicheng Danvin Lee Qicheng - 4 months ago 7
MySQL Question

Combining 2 sql statment

Hi i wanted to ask can any one help me to join this two statement into one

SELECT * FROM worker_leave WHERE YEAR(yearAppplied) = YEAR(DATE_SUB(CURDATE(), INTERVAL 1 YEAR))


And

SELECT * FROM worker_leave WHERE YEAR(yearAppplied) = YEAR(CURDATE())


I want to achieve counting the total leave a person have within current year and previous year total must not be more than 24 (Can be control at php side)

Thanks

Answer
SELECT * FROM worker_leave  
WHERE YEAR(yearAppplied) = YEAR(DATE_SUB(CURDATE(), INTERVAL 1 YEAR)) 
   OR YEAR(yearAppplied) = YEAR(CURDATE())

This will give you combined results for both queries.