SamuraiJack
SamuraiJack

Reputation: 5569

select records between two dates

I have a table something like this..

TeacherName         | Class | Section  | SubjectId |    Date   | ToDate    |Day
--------------------------------------------------------------------------------
       Matt         |   12  | B        | Math      |2013-03-04 |2013-03-14 |Mon
       John         |   12  | A        | Phy       |2013-04-03 |2013-04-12 |Mon

I want a query something like this(not actual sql query)...

Select * 
from Table 
where Class='12' and section='B' and Date= '2013-03-07'

This should give me the first row which has Matt because given date 2013-03-07 lies within that row's date range from 2013-03-04 to 2013-03-14.

Is this even possible?

Upvotes: 0

Views: 3620

Answers (1)

John Woo
John Woo

Reputation: 263933

use BETWEEN

SELECT  * 
FROM    TableName
WHERE   Class = '12' AND 
        Section = 'B' AND 
        '2013-03-07' BETWEEN DATE AND TODATE

Upvotes: 6

Related Questions