Mohamd El-Saleh
Mohamd El-Saleh

Reputation: 21

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

Upvotes: 2

Views: 69

Answers (1)

Will
Will

Reputation: 4469

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

Upvotes: 1

Related Questions