MySQL Forums
Forum List  »  Newbie

Query with MONTH(DATE())
Posted by: angel rivero
Date: March 04, 2011 12:16PM

Hi.

I need with this query that when the current month in the field `_Dates` is null, where condition change to the previous month to the current.

This query is working but you can optimize it?

SELECT `_Dates` 
   FROM _tableDates
      WHERE
         MONTH(`_Dates`) = MONTH(`_Dates`)
         OR MONTH(`_Dates`) = MONTH(`_Dates`)-1

_tableDates example #1
ID	_DATES		NUMBER
1	2010-02-01	33
2	2010-02-02	36

In this table I don't have `_Dates` with current month (3) and I need select current month -1 (2).

_tableDates example #2
ID	_DATES		NUMBER
1	2010-02-01	33
2	2010-02-28	36
3	2010-03-01	36

In this table I have `_Dates` with current month (3) and I need select current month (3).

Can you help me?



Edited 2 time(s). Last edit at 03/04/2011 02:48PM by angel rivero.

Options: ReplyQuote


Subject
Written By
Posted
Query with MONTH(DATE())
March 04, 2011 12:16PM
March 04, 2011 04:11PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.