> Both tables use id field as their primary keys. Managers are also employees, so the two tables share the ids. Since managers have more attributes, their information is stored in a separate table.
> Now we want to find the total income (including the allowance) of each employee (including every manager).
> A JOIN operation is necessary for SQL to do it:
> SELECT employee.id, employee.name, employy.salary+manager.allowance
> FROM employee
> LEFT JOIN manager ON employee.id=manager.id
> But for two tables having a one-to-one relationship, we can treat them like one table:
> SELECT id,name,salary+allowance
> FROM employee
What about employees who aren't managers? I assume they have no entry in the manager table. The SQL would ignore them, because it's a left join, which is not what was asked for. Does the proposed query do the same?
> Now we want to find the total income (including the allowance) of each employee (including every manager).
> A JOIN operation is necessary for SQL to do it:
> But for two tables having a one-to-one relationship, we can treat them like one table: What about employees who aren't managers? I assume they have no entry in the manager table. The SQL would ignore them, because it's a left join, which is not what was asked for. Does the proposed query do the same?What happens if there is also
? Which table is joined?This language seems a little half-baked.