There's no need to perform a count. We only care whether there exists at least one post that meets the criteria, so simply use `SELECT 1 AS has_attachment` and use sql_query_limit() with a limit of 1.