Reputation: 43
In SQL I write a SELECT statement to fetch data between two range dates, using between and ..if i use betwenn ('01/01/2013') and ('31/12/2015') i get all data but i want just between the specified dates...exclude year of 2014
Ex:
select *
from xxx
where date between ('01/01/2013') and ('31/12/2013')
and date between ('01/01/2015') and ('31/12/2015')
But it returned 0 rows.
Upvotes: 0
Views: 389
Reputation: 171579
A succinct way that may not perform as well is:
select *
from xxx
where Year(date) in (2013, 2015)
Upvotes: 1
Reputation: 204924
Use or
instead of and
select *
from your_table
where date between ('01/01/2013') and ('31/12/2013')
or date between ('01/01/2015') and ('31/12/2015')
You don't want data that is in both date ranges what is not possible at the same time. You want data that is in either one of them.
Upvotes: 3