Reputation: 57
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)
Upvotes: 0
Views: 55
Reputation: 124
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.
Upvotes: 4
Reputation: 6669
You can do
SELECT * FROM worker_leave WHERE YEAR(yearAppplied) = YEAR(DATE_SUB(CURDATE(), INTERVAL 1 YEAR))
UNION
SELECT * FROM worker_leave WHERE YEAR(yearAppplied) = YEAR(CURDATE())
Make sure the columns returned by both queries are indentical [in structure]
Upvotes: 1