|
|
|
|
|
by maximilianroos
1002 days ago
|
|
Quoting from https://www.scattered-thoughts.net/writing/against-sql/: --- There are many cases where a small change to a computation requires totally changing the structure of the query, but subqueries are my favourite because they're the most obvious way to express many queries and yet also provide so many cliffs to fall off. -- for each manager, find their employee with the highest salary
> select
> manager.name,
> (select employee.name
> from employee
> where employee.manager = manager.name
> order by employee.salary desc
> limit 1)
> from manager;
name | name
-------+------
alice | bob
---If the inner query has more than one row, the query will raise an error. That's difficult to know from the SQL alone. |
|