0

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)

3
  • 1
    combine them how? the two where clauses are incompatible. a single value in a single field cannot be two different values at the same time. Commented Aug 9, 2016 at 15:13
  • 1
    what about using union all Commented Aug 9, 2016 at 15:18
  • Thanks union is the answer :) Commented Aug 9, 2016 at 15:19

2 Answers 2

4
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.

Sign up to request clarification or add additional context in comments.

Comments

1

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]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.