Please try the following query:
where MastheadUsername = (
from LOCAL_OBJECT_DEFS P
inner join VERSIONS V on P.ID = V.ID AND P.Version = V.LatestVersion
where P.ParentID = 1 AND dbo.fn_ExtractField('CustomSiteName', 0, P.Fields) = 'test1'
AND Name = 'I''m deleting this baseline'
My baseline was located in the custom site “test1” and it’s name was: "I’m deleting this baseline"
Note in a query a single quote in a name had to be repeated twice.