Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

>what if we want to return the salary too?

>the only solution is to change half of the lines in the query

How about adding a second subquery for the salary.



It is a toy example. Perhaps imagine a more realistic subquery that is much longer. Are you going to duplicate a 50 line subquery to get the salary when all you want is one more value? No, you'd probably want to restructure the query with a join or CTE instead. To the author's point, a large change relative to the gain.


The author explicitly said "the only solution" and that's plain wrong.


No, I will write a SQL function for the subquery and call it from the main query.


This example seemed wrong to me as well. You can have a subquery, or CTE that returns as many fields as you want and can join on the manager key


An additional subquery and a CTE are both restructuring the query significantly, which is the author's point.


Well if he is insisting in doing the SQL version of writing everything inside a lambda without modularizing the code, then yeah that is bound to happen.


There's already a subquery in there. I'm saying this can still be done with one subquery, just in a different place and it returns the desired results.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: