スペースタイム
スペースタイム

Reputation: 159

Filter All Data Using Start and End Date Column

How should I filter all data from start to end date? I have 2 columns - one for the start date and another for the end column.

I want to select all the data having a specific start and end date.

For example:
August 2018 to September 2018

Data:

enter image description here

Here's my query:

SELECT * FROM project_monitoring pm INNER JOIN status s ON pm.status_ID = s.status_ID WHERE /*select all started from this date format MDY or MY or Y */ pm.proj_DateStarted = '2018-04-19' /*this end date format MDY or MY or Y */ pm.proj_DateEnded = '2018-03-08' 

Upvotes: 0

Views: 1042

Answers (3)

Mukul_Vashistha
Mukul_Vashistha

Reputation: 106

SELECT * FROM Table_name WHERE (start_date BETWEEN aaa AND bbb ) AND (last_date BETWEEN ccc AND ddd) .

I think this should work pretty straightforward if I am understanding the question right.

Upvotes: 1

Daniel Marcus
Daniel Marcus

Reputation: 2686

Is this what you are looking for?

select * from project_monitoring pm 
INNER JOIN status s ON pm.status_ID = s.status_ID 
where pm.proj_datestarted>=yourstartdate and 
pm.proj_dateended<=yourenddate 

Upvotes: 1

D-Shih
D-Shih

Reputation: 46239

If I understand correct.

You can try to use BETWEEN

SELECT * FROM project_monitoring pm 
INNER JOIN status s ON pm.status_ID = s.status_ID 
WHERE (pm.proj_DateStarted BETWEEN '2018-08-01' AND '2018-09-01') 
OR (pm.proj_DateEnded BETWEEN '2018-08-01' AND '2018-09-01')

Upvotes: 2

Related Questions