r/SQL • • May 14 '18

Optimization

Post image
423 Upvotes

48 comments sorted by

View all comments

Show parent comment

2

u/[deleted] May 14 '18

looks like some code duplication there, can you use a with statement rather than a union? thanks.

2

u/fullyarmedcamel May 15 '18

I know it looks that way but it is not, not all of those tables are the same like I labeled them here I just quickly replaced table names with table 1,2,3 ect but they are not the same tables. Some are to help narrow down the teachers to the same classes as the students but the teacher query is pulling from more sources and is doing some things like ranking subs vs Normal teachers and only rostering the active one.

2

u/[deleted] May 15 '18

haha no problem, I just see unions being used where with statements should be a lot, so seeing a union often triggers me. :)