gilas
gilas

Reputation: 43

How get data between two ranges dates

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

Answers (2)

D'Arcy Rittich
D'Arcy Rittich

Reputation: 171579

A succinct way that may not perform as well is:

select * 
from xxx 
where Year(date) in (2013, 2015)

Upvotes: 1

juergen d
juergen d

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

Related Questions