I am trying to speed up a PHP script and I am currently pushing some PHP logic in the Mysql domain of the thing. Is there a way to make a different select query if the first
One option would be to use UNION ALL with EXISTS:
SELECT *
FROM proxies
WHERE A='B'
UNION ALL
SELECT *
FROM proxies
WHERE A='C' AND NOT EXISTS (
SELECT 1
FROM proxies
WHERE A='B'
)
This will return rows from the proxies table where A='B' if they exist. However, if they don't exist, it will look for those rows with A='C'.