Optimizing SQL: Removing queries inside loops | Hacker News Reader