Canta
Canta

Reputation: 23

MYSQL select with 2 dates condition

In my database, I have 2 different dates. A move date and a event date. I would like to run a query by event date. But if there is no event date, so i want use the move date. Is there a MYSQL code that does this? Like this: "where if .." Of course the result is in descending order date. Thanks !

Upvotes: 0

Views: 69

Answers (2)

luna80
luna80

Reputation: 153

use the "case" condition

SELECT CASE WHEN movedate != NULL THEN movedate ELSE eventdate END AS selecteddate

Upvotes: 0

Ismail MANAREDDINE
Ismail MANAREDDINE

Reputation: 99

try this one like where coalesce(event_date, move_date) >= ?

Upvotes: 1

Related Questions