[RESOLVED] Fetching Last Month Records-Need Clarification
I need one clarification.. i'm in a need to fetch all records from employee table(i.e last month record eg. if this month is May means i wanna fetch april month records.).. I hav used a mysql query(am using jsp)
Query1 : select * from empadvanceamount where Date >= DATE_SUB(CURDATE(),INTERVAL 1 MONTH) and Empid=?
if am using the above query means i cant able to fetch last month records..
Query2: select * from empadvanceamount where Date between DATE_SUB(CURDATE(),INTERVAL 1 MONTH) and Empid=?
but if am using the above query with 'between' means i can fetch records...
Please explain me the difference ..as am newbie to this mysql....Thanks in advance....
if you want to fetch ALL the records of previous month then this will work better:
That way you will always fetch the first day till the last day of the previous month.
select * from empadvanceamount where
MONTH(date) = MONTH(now() - INTERVAL 1 MONTH)
YEAR(date) = YEAR(now() - INTERVAL 1 MONTH)
Thank u very much qrizly....thats very helpful.......
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)