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 - 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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Limit results with TOP4m 39s
-
(Locked)
Remove duplicates with DISTINCT2m 53s
-
(Locked)
Comparison operators3m 43s
-
(Locked)
Understand NULL values4m 42s
-
(Locked)
Match text with LIKE and wildcards4m 36s
-
(Locked)
Challenge: Retrieve matching text strings49s
-
(Locked)
Solution: Retrieve matching text strings4m 52s
-
(Locked)
Solution: Filter results from a query result4m 28s
-
-
-
-
-
-
-
-
-