SQL Server Articles, SQL Server Tips, SQL Server Tutorials, SQL Server Tuning, SQL Server DBA, SQL Server Basics, Training, etc - MyTechMantra.com

SQL Server SELECT DISTINCT Clause T-SQL Tutorial with Examples

Previous Page.. Begin Tutorial.. Next Page..

The SELECT DISTINCT Statement is used to fetch distinct values in a specific column of a given table. This article gives you an overview of the SQL Server SELECT DISTINCT clause or SELECT DISTINCT SQL Clause.

This is Part 3 of 40 Part SQL Server T-SQL Tutorial. Click here to read it from the beginning….

SQL SELECT DISTINCT Statement

The SQL DISTINCT clause removes duplicates from the result set of a SELECT statement in SQL Server.

SELECT DISTINCT Syntax | SQL Server SELECT DISTINCT Statement

Use <DatabaseName>
GO

SELECT DISTINCT (column1)
	FROM schema.table
GO

Note: To fetch unique records from a SQL Server Database Table, one needs to use DISTINCT SQL Keyword.

SQL Server SELECT DISTINCT Statement: How to Query Distinct Records from a Table in SQL Server

SELECT DISTINCT Clause Example

Execute the below query will fetch all Distinct First Name’s (Column FirstName) from Person table.

Use AdventureWorks2016
GO

SELECT 
	  DISTINCT FirstName
FROM Person.Person
GO
SELECT DISTINCT Records from a Table in SQL Server


When you need to SELECT UNIQUE records from a SQL Server Database Table, one needs to use SELECT DISTINCT in the SQL Server.

SELECT DISTINCT Multiple Columns Example

Execute the below query will fetch all the records which are distinct for FirstName and LastName from Person’s table.

Use AdventureWorks2016
GO

SELECT 
	  DISTINCT FirstName 
		  , LastName
FROM Person.Person
GO
SELECT DISTINCT Multiple Columns Records from a Table in SQL Server

Click Next Page button to continue reading the topics and click on the Previous Page button to revisit the previous topic.

Previous Page.. Begin Tutorial.. Next Page..



Ashish Mehta

Ashish Kumar Mehta is a database manager, trainer and technical author. He has more than a decade of IT experience in database administration, performance tuning, database development and technical training on Microsoft SQL Server from SQL Server 2000 to SQL Server 2014. Ashish has authored more than 325 technical articles on SQL Server across leading SQL Server technology portals. Over the last few years, he has also developed and delivered many successful projects in database infrastructure; data warehouse and business intelligence; database migration; and upgrade projects for companies such as Hewlett-Packard, Microsoft, Cognizant and Centrica PLC, UK. He holds an engineering degree in computer science and industry standard certifications from Microsoft including MCITP Database Administrator 2005/2008, MCDBA SQL Server 2000 and MCTS .NET Framework 2.0 Web Applications.

Add comment

Newsletter Signup! Join 15,000+ Professionals




Be Social! Like & Follow Us

Follow us

Don't be shy, get in touch. We love meeting interesting people and making new friends.

Advertisement