Jonline
Jonline

Reputation: 1747

MySQL: TIMESTAMPDIFF() condition having no effect

I am truly puzzled. The statement below returns the same whether I turn the final clause to

TIMESTAMPDIFF( 
    SECOND ,  `Regkey`.`expires` , NOW( ) ) > 0


TIMESTAMPDIFF( 
    SECOND ,  `Regkey`.`expires` , NOW( ) ) < 0


TIMESTAMPDIFF( 
    SECOND ,  `Regkey`.`expires` , NOW( ) ) = 0

And here's the main statement

SELECT  `Regkey`.`id` ,  `Account`.`id` ,  `Account`.`name` 
FROM  `databasename`.`regkeys` AS  `Regkey` 
LEFT JOIN  `databasename`.`accounts` AS  `Account` ON (  `Regkey`.`account_id` =  `Account`.`id` ) 
LEFT JOIN  `databasename`.`groups` AS  `Group` ON (  `Regkey`.`group_id` =  `Group`.`id` ) 
WHERE  `Regkey`.`keyval` =  'skdfj908asf7hasf6546753gpd8'
AND  `Regkey`.`type` = 1
AND  `Regkey`.`group_id` = 3
OR  `Regkey`.`group_id` = 0
AND  `Regkey`.`uses` >  `Regkey`.`maxuses` 
AND  `Account`.`students` >0
AND TIMESTAMPDIFF( 
SECOND ,  `Regkey`.`expires` , NOW( ) ) >0
GROUP BY account_id

Anyone? :)

Upvotes: 0

Views: 331

Answers (1)

Guillermo Mansilla
Guillermo Mansilla

Reputation: 3879

I see that your condition is part of a "OR" group, thus it doesnt matter if your condition evaluates to true or false.

What I suggest here, just for testing purposes is to write your query with only one condition, that is, TIMESTAMPDIFF( ....

Upvotes: 1

Related Questions