0

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.

2
  • 1
    Use Or instead of And Commented Jul 23, 2015 at 15:24
  • thanks man ...it works perfectly Commented Jul 25, 2015 at 8:06

2 Answers 2

3

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.

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

Comments

1

A succinct way that may not perform as well is:

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.