

So, in this case, the statement will return distinct rows for FirstName and LastName.

SELECT DISTINCT TOP 10 FirstName, LastName FROM Person.Person ORDER BY LastName Let’s look at the first statement who purpose is to return a unique list of fist and last names. I thought everyone would like to know the answer so I create a blog post. What about Select Distinct TOP 10 LastName, FirstName + ' ' + LastName AS FullName FROM Person.Person ORDER BY LastName Is this looking at distinct first names? Distinct combined first and last names? How do we distinguish between the columns used for the distinct evaluation and columns we just want to show in the output? For example, SELECT DISTINCT TOP 10 FirstName, LastName FROM Person.Person ORDER BY LastName I’m a bit confused about SELECT DISTINCT and SELECT. Here is the question that Nan originally sent me:

How do the SQL Top and Distinct SELECT modifiers Work Together to Produce Results? Nan’s Original Question You can get started using these free tools using my Guide Getting Started Using SQL Server.
#Postgresql select distinct series#
This article is inspired by a series of questions that one of my readers, Nan, recently sent me regarding SQL DISTINCT, TOP, and ORDER BY.Īll the examples for this lesson are based on Microsoft SQL Server Management Studio and the AdventureWorks2012 database.
