O'Reilly logo

Microsoft Azure SQL Data Warehouse - Architecture and SQL by Todd Wilson, Tom Coffing

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 8 – Distinct, Group By and TOP

“A bird does not sing because it has the answers, it sings because it has a song.”

- Anonymous

The Distinct Command

image

DISTINCT eliminates duplicates from returning in the Answer Set.

Distinct vs. GROUP BY

image

Both examples produce the exact same result

 Class_Code

   ?

   FR

   JR

   SO

   SR

Rules for Distinct Vs. GROUP BY

(1) Many Duplicates – use GROUP BY

(2) Few Duplicates – use DISTINCT

(3) Space Exceeded - use GROUP BY

Distinct and GROUP BY in the two examples return the same answer set.

Quiz – How many ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required