Using MySQL and php, how could I get all the results in one query that match a particular query, but if the results are not found, it finds all the results by default? For example, I have this query:
SELECT * FROM table1 WHERE typeid = 5
If the results are not found from the query below, I want to find all the results from table1 with type 1:
SELECT * FROM table1 WHERE typeid = 1
How can I do this in a single request? If I try the following query, I get both 5 and 1:
SELECT * FROM table1 WHERE typeid = 5 OR typeid = 1
All I want is a query table1 for all records assigned using typeid of 5, if no results are found, then all results are assigned typeid = 1 in one query. How can i do this? Or should I have 2 requests?
EDIT
I need this for multiple returned records, not a single record.