This is probably something simple, but I just can't think of how to do it. I have a table called categories with two columns, Key and Category. I want to select the keys from the table for one value as a Main category, and one as a Sub category. So, I have a query as follows:
SELECT MainCatKey,SubCatKey FROM
(SELECT `Key` AS MainCatKey FROM categories WHERE Category = 'some category name') AS MainCat,
(SELECT `Key` AS SubCatKey FROM categories WHERE Category = 'some other category name') AS SubCat
The problem is that if one of the categories doesn't exist, then the query returns no rows. What I really want is that if one of the subqueries returns no rows, I still get a result set, but with NULL for the empty result. Using the above example, if 'some category name' didn't exist, but 'some other category name' did exist, and had a Key of 123, then I'd want to get a result set of
MainCat | SubCat
NULL | 123
rather than just an empty result.