PREFIX : <http://example/>
PREFIX rdf:    <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT ?p
{
    { ?x rdf:type :X . } UNION { ?x rdf:type :X . FILTER (?x != :x2 )}
    OPTIONAL { ?x :p ?p . }
}
GROUP BY ?p
