Optimal Way to Avoid Duplicate SubQuery in SQL
|Added at||2016-12-30 20:12|
I have a simple two column table. For example's sake we can use the following to build the data:
There are two rows that are identical. There is also a question that appears on multiple assignments. The latter is a valid scenario, and I am trying to get a query of all the questions that are part of multiple assignments. So my desired output is:
I was able to get this results with this:
As you can see the DISTINCT subquery is being repeated twice. I could avoid this by using the WITH command, but my understanding is that this does not necessarily mean that the subquery will be executed only once. So now I am here in StackOverflow, to ask if anyone knows a more efficient way to run this query.