While working on a oracle SQL , noticed that adding a column to the selected columns increases the total rows in the result. The query is using multiple subqueries declared using WITH. The join in the final query is a left join. Why is the row count getting impacted?
1 Answer
The only way I can think of to increase the number of result rows by adding a column to the SELECT clause is when using SELECT DISTINCT.
SELECT DISTINCT removes duplicates from the results, so
col1 col2 a b a b a c a c
becomes
col1 col2 a b a c
When adding a column
col1 col2 col3 a b d a b e a c f a c f
becomes
col1 col2 col3 a b d a b e a c f
for instance, which is one row more than before.
distinctkeyword?