Q:

SQL Subquery Optimization

I have two tables, Categories and RecipeCategories
**Categories**
CategoryID varchar (Primary Key)
Name varchar

**RecipeCategories**
RecipeID varchar
CategoryID varchar
Composite primary key

I'm searching for a way to return CategoryID and Name for all categories, plus whether or not the recipe is actually in that category.  I could use something like
SELECT c.CategoryID, c.Name, 
         (SELECT COUNT(*) 
          FROM RecipeCategories 
          WHERE RecipeID = @recipeId AND CategoryID = c.CategoryID))
FROM Categories c

But I don't think that would scale if the table gets too big. 

A:

SELECT c.CategoryID
     , c.Name
     , Case When (r.RecipeID is null) Then 'No' Else 'Yes' End
  FROM Categories c
  left join RecipeCategories r on r.CategoryID = c.CategoryID
                              and r.RecipeID = @recipeId

