Guest User

Untitled

a guest
Aug 20th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. How to reduce the need for these MySQL subqueries?
  2. SELECT
  3. p.something,
  4. p.otherthing,
  5. c.athing,
  6. d.nothing,
  7. (select startdate from dbo.aqcprojects where projectid = p.id and aqcphase = 1) as 'Phase 1 start',
  8. (select finishdate from dbo.aqcprojects where projectid = p.id and aqcphase = 1) as 'Phase 1 end',
  9. (select startdate from dbo.aqcprojects where projectid = p.id and aqcphase = 2) as 'Phase 2 start',
  10. (select finishdate from dbo.aqcprojects where projectid = p.id and aqcphase = 2) as 'Phase 2 end',
  11. **the above four lines repeated ad nauseum.
  12. FROM
  13. bunch of joins
  14.  
  15. SELECT
  16. p.something,
  17. p.otherthing,
  18. c.athing,
  19. d.nothing,
  20. project_phase_1.startdate as 'Phase 1 start',
  21. project_phase_1.finishdate as 'Phase 1 end',
  22. project_phase_2.startdate as 'Phase 2 start',
  23. project_phase_2.finishdate as 'Phase 2 end',
  24. **the above four lines repeated ad nauseum.
  25. FROM
  26. projects AS p
  27. LEFT JOIN dbo.aqcprojects AS project_phase_1 ON project_phase_1.projectid = p.id
  28. LEFT JOIN dbo.aqcprojects AS project_phase_2 ON project_phase_2.projectid = p.id
  29. bunch of joins
  30. WHERE project_phase_1.aqcphase = 1 AND project_phase_2.aqcphase = 2
Add Comment
Please, Sign In to add comment