The below SQL query is working for me, but it returns the property value when there staffNo is null 6 times(Once for each staff member). I want to return the property owner even if the staffNo is null, without 6 returns.
SELECT s.branchNo, s.staffNo, s.fName, s.lName, propertyNo, p.staffNo,
o.fName, o.lName, o.ownerNo
FROM staff s, propertyforrent p, privateowner o
WHERE s.staffNo = p.staffNo AND o.ownerNo = p.ownerNo
OR p.staffNo IS NULL AND o.ownerNo = p.ownerNo
ORDER BY s.branchNo, s.staffNo, propertyNo
Results
B003 SG14 David Ford PG16 SG14 Tony Shaw CO93
B003 SG14 David Ford PG4 NULL Tina Murphy CO40
B003 SG37 Ann Beech PG21 SG37 Carol Farrel CO87
B003 SG37 Ann Beech PG36 SG37 Tony Shaw CO93
B003 SG37 Ann Beech PG4 NULL Tina Murphy CO40
B003 SG5 Susan Brand PG4 NULL Tina Murphy CO40
B005 SL21 John White PG4 NULL Tina Murphy CO40
B005 SL41 Julie Lee PG4 NULL Tina Murphy CO40
B005 SL41 Julie Lee PL94 SL41 Carol Farrel CO87
B007 SA9 Mary Howe PA14 SA9 Joe Keogh CO46
B007 SA9 Mary Howe PG4 NULL Tina Murphy CO40
Here is the desired result
B003 SG14 David Ford PG16 SG14 Tony Shaw CO93
B003 SG14 PG4 NULL Tina Murphy CO40
B003 SG37 Ann Beech PG21 SG37 Carol Farrel CO87
B003 SG37 Ann Beech PG36 SG37 Tony Shaw CO93
B005 SL41 Julie Lee PL94 SL41 Carol Farrel CO87
B007 SA9 Mary Howe PA14 SA9 Joe Keogh CO46
Thanks in advance!
WHERE (o.ownerNo = p.ownerNo) AND ((s.staffNo = p.staffNo) OR p.staffNo IS NULL)). note the bracketing.