I have a table1 that hold ranges

rangeId, rangeName, fromDate, toDate,cat

another table2 has rows


I need to

select  all rows
from table2
that table2.rowDate is between table1.fromDate
                           and table1.toDate
and cat = 1
  • What did you try? What did you get?
    – Marco
    May 23, 2016 at 9:33

1 Answer 1


Something like :

select t2.*
from table2 t2
join table1 t1 on t2.rowdate between t1.fromDate and t1.toDate
where t1.cat = 1
  • 1
    sqlblog.org/2009/10/10/… May 23, 2016 at 10:00
  • 2
    @Michael * doesn't bother me too much since columns are not mentioned in the question. Something such as ... would have been better though. What bother me here is the data comparaison using between. sqlblog.org/2009/10/16/… A better choice is t2.rowdate >= t1.fromDate and t2.rowDate < t1.toDate (using <, <=, >=, > whether it is inclusive or exlusive ranges) May 23, 2016 at 12:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.