vendredi 26 décembre 2014

MySQL WHERE if NULL select another column


This is my mysql table



id date_created date_active
1 2014-06-07 18:24:38 NULL
2 2014-06-07 18:24:38 2014-06-07 18:24:38
3 2014-06-07 18:24:38 2014-06-07 18:24:38
4 2014-06-07 18:24:38 NULL
5 2014-06-07 18:24:38 NULL
6 2014-06-07 18:24:38 NULL
7 2014-06-07 18:24:38 2014-06-07 18:24:38
8 2014-06-07 18:24:38 2014-06-07 18:24:38
9 2014-06-07 18:24:38 2014-06-07 18:24:38
10 2014-06-07 18:24:38 NULL


How to set WHERE to select another column if the column is NULL?



SELECT *
FROM TABLE
WHERE date_active = 'value'.


If date_active is NULL it should use the date_created column.





Aucun commentaire:

Enregistrer un commentaire