Mohamd El-Saleh Mohamd El-Saleh - 15 days ago 8
MySQL Question

How can I put (IF)condition in my SQL code?

I need to put (IF) condition in my code to show only the datediff bigger than 0 but always happen error , anybody can help me please ?

SELECT DATEDIFF(`Date` ,CURDATE()) AS Date,`id` AS Dateid
FROM `election`
ORDER BY `Date` ASC


enter image description here

i need only Date bigger than 0

Answer

Not very pretty, but you can just recreate the date field in the where clause to compare it:

SELECT DATEDIFF(`Date` ,CURDATE()) AS Date,`id` AS Dateid
FROM `election`
WHERE DATEDIFF(`Date` ,CURDATE()) > 0
ORDER BY `Date` ASC
Comments