I have the following Query:
SELECT IF(TIMESTAMPDIFF(HOUR,users_codes.timestam,CURRENT_TIMESTAMP()) < 48,'no','yes') AS Expired
FROM users_codes
How do I return only rows that have 'no'?
add a WHERE condition. You cannot use the ALIAS on the where clause.
SELECT IF(TIMESTAMPDIFF(HOUR,users_codes.timestam,CURRENT_TIMESTAMP()) < 48,'no','yes') AS Expired
FROM users_codes
WHERE IF(TIMESTAMPDIFF(HOUR,users_codes.timestam,CURRENT_TIMESTAMP()) < 48,'no','yes') = 'no'
or use a subquery
SELECT *
FROM
(
SELECT IF(TIMESTAMPDIFF(HOUR,users_codes.timestam,CURRENT_TIMESTAMP()) < 48,'no','yes') AS Expired
FROM users_codes
) s
WHERE Expired = 'no'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With