Hmm.

Bit Odd. However, I suspect the problem is that your 'where' isn't explicit
enough:

Where ( month(date) = month(now()) ) or ( month(date) = month(now())-1 )

Bear in mind that if month(now()) = 1 you will be looking for records in
month 0!

A better way to do this might be:

WHERE month(date) BETWEEN month(now() - interval 1 month) AND month(now)

Cheers,

Matt

> -----Original Message-----
> From: mayuran [mailto:[EMAIL PROTECTED]
> Sent: 03 May 2004 16:15
> To: [EMAIL PROTECTED]
> Subject: WHERE clause problem
> 
> This is my table:
> mysql> desc testing;
> +-------+------+------+-----+---------+-------+
> | Field | Type | Null | Key | Default | Extra |
> +-------+------+------+-----+---------+-------+
> | date  | date | YES  |     | NULL    |       |
> +-------+------+------+-----+---------+-------+
> 
> 
> Here are the values:
> 
> mysql> select *from testing;
> +------------+
> | date       |
> +------------+
> | 2004-04-10 |
> | 2004-04-15 |
> | 2004-01-01 |
> +------------+
> 
> Here is my question:
> 
> The following query returns incorrect rows and I dont understand why.
> 
> mysql> SELECT * FROM testing WHERE MONTH(date) = (MONTH(NOW()) OR
> MONTH(NOW())-1);
> +------------+
> | date       |
> +------------+
> | 2004-01-01 |
> +------------+
> 
> I wanted the query to return the rows whose months are from this month
> or last month.
> 
> This query however, returns the correct rows:
> mysql> SELECT * FROM testing WHERE MONTH(date) = MONTH(now()) OR
> MONTH(date) = MONTH(NOW())-1;
> +------------+
> | date       |
> +------------+
> | 2004-04-10 |
> | 2004-04-15 |
> +------------+
> 
> Why does the first one not work? its shorter to type :)
> 
> Thanks
> 
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]




-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to