I am trying to run this MySQL query from PHP app.
SELECT * FROM LIVE WHERE STATUS=1 AND (CRITERIA='demo' OR CRITERIA='all' OR CRITERIA='1' OR CRITERIA='1E')
Which is working perfectly. However I want that if this query returns nothing then it should execute another query somewhat like this.
SELECT * FROM LIVE WHERE STATUS=0 AND (CRITERIA='demo' OR CRITERIA='all' OR CRITERIA='1' OR CRITERIA='1E')
I have tried multiple things like SELECT IF or SELECT IFNULL but none of them seems to work. What am I doing wrong? Basically I want that if the first query returns row then give that but if not then run the second query.
Now I saw this question on stackoverflow - Second SELECT query if first SELECT returns 0 rows . I tried it but in return i got this error Unrecognized statement type. (near "IF" at position 0)
CASE
in theSELECT
but currently its a bit hard to visualize what you're trying to achieve. If you have sample data, results of your current query and your expected result, it would be much easier to help you. – FaNo_FN Oct 22 '20 at 5:33