PREFIX  foaf:   <http://xmlns.com/foaf/0.1/>
PREFIX    ex:   <http://example.org/things#>
SELECT ?id ?ssn
WHERE 
{ 
    ?person 
        a foaf:Person;
        foaf:name ?name . 
    GRAPH ?x { 
        [] foaf:name ?name;
           foaf:nick ?nick
    } 
    OPTIONAL { 
        { ?person ex:empId ?id } UNION { ?person ex:ssn ?ssn } 
    } 
} 