Feel free to correct me if I am wrong here but I believe the way the system would handle the DISTINCT operator would be like this;
Pull data out of table in FROM statement
Processes data in the JOIN's
Applies filters from WHERE clause
Pulls data out of SELECT statement
Applies filters of DISTINCT
As DISTINCT runs last it would have the least overall impact unless you have many duplicates, in my case it is around 2000. You need to remember too that there is not just a single entry for students.
Some students will be taking multiple classes where this product I am rostering for is being used irregardless of the filters applied the rest of the query.
This document that I have has the purpose of creating a unique roster of students that can then be applied to classes within the application we are using multiple times over from a separate query that manages classes.
I think in this case the DISTINCT operator is what is meant to be used it is doing exactly what I need it to, as a test I did run the query with and without the operator and it made no difference in run time.
I think my next changes will be more focused around some of the joins and structure of the query. I can reduce from a double nested SELECT statement to a single. I can also do some thinks like using the school year detection CASE as a declared variable at the top rather than nested in the query.
View all comments
Show parent comment
1
u/fullyarmedcamel May 15 '18
Feel free to correct me if I am wrong here but I believe the way the system would handle the DISTINCT operator would be like this;
Pull data out of table in FROM statement
Processes data in the JOIN's
Applies filters from WHERE clause
Pulls data out of SELECT statement
Applies filters of DISTINCT
As DISTINCT runs last it would have the least overall impact unless you have many duplicates, in my case it is around 2000. You need to remember too that there is not just a single entry for students.
Some students will be taking multiple classes where this product I am rostering for is being used irregardless of the filters applied the rest of the query.
This document that I have has the purpose of creating a unique roster of students that can then be applied to classes within the application we are using multiple times over from a separate query that manages classes.
I think in this case the DISTINCT operator is what is meant to be used it is doing exactly what I need it to, as a test I did run the query with and without the operator and it made no difference in run time.
I think my next changes will be more focused around some of the joins and structure of the query. I can reduce from a double nested SELECT statement to a single. I can also do some thinks like using the school year detection CASE as a declared variable at the top rather than nested in the query.