Forum Discussion
MrPatrick
Helper I
4 years agoRestricting data import by date - MySQL
I've got a database where all the tables go back to ~2013 but I'm only interested in the last 12 months. Currently I either import the whole lot and then filter it (which is incredibly slow and prone...
- 4 years ago
Why not make the start date dynamic on your query? In T-SQL it would be.
WHERE Event_Date >= DATEADD(MONTH,-12,CONVERT(DATE,GETDATE()))
jdbuchanan71
Super User
4 years agoWhy not make the start date dynamic on your query? In T-SQL it would be.
WHERE Event_Date >= DATEADD(MONTH,-12,CONVERT(DATE,GETDATE()))
MrPatrick
Helper I
4 years agoGreat thank you, I cna't believe I hadn't thought of this beforehand.
for the record im in MySQL so the query was
select * from sales
where order_date> now() - INTERVAL 12 month;