dimanche 29 avril 2018

MySQL first condition match priority

I have this data

+----+--------+---------------------------------+
| id | fromid |            message              |
+----+--------+---------------------------------+
|  1 |  1213  | this is just an example         |
+----+--------+---------------------------------+
|  2 |  1992  | other random message            |
+----+--------+---------------------------------+
|  3 |  1364  | example number three            |
+----+--------+---------------------------------+

I need to search data where fromid='1992' or message LIKE '%example%'

if there is any result where fromid matches 1992 value, return this result, and ignore second condition

but if there is no result from first condition (fromid='1992'), return the result from second condition

can I do that on single query?

Aucun commentaire:

Enregistrer un commentaire