From the course: Querying Microsoft SQL Server 2022

Unlock the full course today

Join today to access over 24,200 courses taught by industry experts.

Remove duplicates with DISTINCT

Remove duplicates with DISTINCT - SQL Server Tutorial

From the course: Querying Microsoft SQL Server 2022

Remove duplicates with DISTINCT

- [Instructor] One useful piece of information that you can pull from a database is to find out how many times a specific value appears in a table. For instance, if we start a new query and I say SELECT * FROM Person.Address, you'll see that this contains a total of over 19,000 rows of individual address data for our customers. Now, one of these columns in this table is the City column. And as you'd expect, there's lots of people that live in the same city represented in this dataset. One question that you might ask is, "Well, how many cities are there?" You might be tempted to get the answer just by selecting the City column from the table. Let's go ahead and change our query to just SELECT City. Now, when I re-execute it, you'll see we get a column of just our cities. However, if you take a look at the number, it's still returning 19,614 rows. They're displaying in a different order, but you can already see here that…

Contents