How To Write Tables In Sql With A Disjoint Connection
So I have three tables which I want to create with a disjoint Connection. These are person, Tenant and employee. So every person must either be a Tenant or an employee, never both
Solution 1:
You can try this, which will pick out every person who is EITHER a person OR an employee:
SELECT *
FROM (SELECT person.*,
CASEWHEN employee.id IS NULL THEN0ELSE1ENDAS is_employee,
CASEWHEN tenant.id IS NULL THEN0ELSE1ENDAS is_tenant
FROM person LEFT JOIN employee on person.id = employee.id
LEFT JOIN tenant on person.id = tenant.id) AS tA
WHERE tA.is_employee <> tA.is_person
Make sure that the id columns are all indexed.
Post a Comment for "How To Write Tables In Sql With A Disjoint Connection"