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