0

i want the record of employee who applied leave form '2016-03-16' date to '2016-03-25' date. But when i will write my query in which i would mention the between clause in where condition,like i mention the date

select * from leave_form 
where from_date and to_date between '2016-03-16' and '2016-03-25' 
     and status='yes' and emp_code='K0209';

it will show me result like

type, emp_code, rm_id, leave_bal, from_date, leave_from, to_date,   leave_to, number, leave_for, status, applied_date, pendays,  personal,
K0209, K0093, 10, 2016-03-16, full day, 2016-03-25, full day, 10, personal, yes, 2016-03-15, 

but also when i will write my query like

 select * from leave_form 
 where from_date and to_date between '2016-03-17' and '2016-03-17' 
     and status='yes' and emp_code='K0209';

it have to show me the same result indicating that you have already applied for this dates. i.e it will show the same result:

type, emp_code, rm_id, leave_bal, from_date, leave_from, to_date, leave_to, number, leave_for, status, applied_date, pendays
personal, K0209, K0093, 10, 2016-03-16, full day, 2016-03-25, full day, 10, personal, yes, 2016-03-15, 
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
shyarry g
  • 345
  • 1
  • 3
  • 8
  • I'm not sure that this part of your request does what you want it to do : `where from_date and to_date between` . I don't know the priorities of the different operators here, but I'm quite sure it does check that both columns contain dates between those specified later in the query. – Loufylouf Mar 25 '16 at 07:58
  • not clear what you need...you are using between clause wrongly as there is two columns from_date and to_date....so you need to use 2 between clause for both fields otherwise you need to follow as @Harry suggested in his answer. – Zafar Malik Mar 25 '16 at 09:21

1 Answers1

0

Your question is confusing. Does this help...

select * 
   from leave_form 
 where from_date  > '2016-03-16' 
   and to_date    < '2016-03-25' 
   and status   ='yes' 
   and emp_code ='K0209';
Harry
  • 11,298
  • 1
  • 29
  • 43