0

I was asked to write an MYSQL code that returns data from specific dates (2003-2005 December only)from my database. I, however, cannot figure out why I am getting no data returned. The code I am using is below. I tried to use the BETWEEN clause but I still get no data returned. Any help is greatly appreciated.

select 
paymentDate, amount, discounted
From 
payments
where 
paymentDate >= 2003-12-01 and paymentDate <= 2003-12-31
and paymentDate >= 2004-12-01 and paymentDate <= 2004-12-31
and paymentDate >= 2005-12-01 and paymentDate <= 2005-12-31
Order by paymentDate;

1 Answers1

0

Because the paymentDate may not be simultaneously in December of each of those years.
Instead connect each of the December conditional statements with or.
Also I included ANSI syntax for the dates, i.e. date '2003-12-01'

where 
(paymentDate >= date '2003-12-01' and paymentDate <= date '2003-12-31'
 or paymentDate >= date '2004-12-01' and paymentDate <= date '2004-12-31'
 or paymentDate >= date '2005-12-01' and paymentDate <= date '2005-12-31')
mechanical_meat
  • 163,903
  • 24
  • 228
  • 223