Database of students in a social network
Style


Indentation would make your query more readable.
Table names in MySQL may be case sensitive, depending on the underlying filesystem.  Therefore, it is safest to write the query using identifiers with the same case as stated in the problem.
SQL keywords are conventionally written in ALL CAPS, though some programmers object to that convention.
Single-letter names for table aliases are cryptic.  While I can somewhat understand friend f, I have a harder time accepting highschooler a.


Formulation


UNION, short for UNION DISTINCT, automatically deduplicates the result set.  If possible, prefer UNION ALL for efficiency.  However, in this case, you do need deduplication for the correct answer.
The two halves of the union seem repetitive.
Subtracting one from the final count is weird and risky.  I suggesting filtering out Cassandra herself from the result set.


Here's how I would write it:

SELECT count(Friend.ID1)
    FROM Highschooler AS Cassandra, Friend
    WHERE
        Cassandra.name = 'Cassandra'
        AND (
            Friend.ID2 = Cassandra.ID
            OR Friend.ID2 IN (
                SELECT Friend.ID1
                    FROM Friend
                    WHERE Friend.ID2 = Cassandra.ID
            )
        )
        AND Friend.ID1 &lt;&gt; Cassandra.ID;