3 ms·
> 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 infor
by twic 2y ago
> 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?
What happens if there is also
salesperson table
id
allowance
? Which table is joined?
This language seems a little half-baked.