dimanche 22 novembre 2015

mySQL IF column contains specific data, display that column, else display another column

I want to create a query that, based on the data, can display one of three columns.

I have three date columns: Date1, Date2, Date3. If Date1 is not equal to '0000-00-00 00:00:00' AND is smaller than "<" NOW(), display that column. If both of these values aren't satisfied, then look at Date2 for the same query. If that isn't satisfied then look at Date3.

Here's the syntax I tried piecing together:

SELECT ID, Type, Status, IF (Date1 <> '0000-00-00 00:00:00' AND < NOW() THEN Date1 ELSEIF Date2 <> '0000-00-00 00:00:00' AND < NOW() THEN Date2 ELSEIF Date3 <> '0000-00-00 00:00:00' AND < NOW() THEN Date3) AS col1 FROM tableA

Any help would be greatly appreciated!

Aucun commentaire:

Enregistrer un commentaire