---
title: "SQL Query to Get Distinct Values from a Column in SQL Server"  
description: "SQL Query to Get Distinct Values from a Column in SQL Server"  
author: "Ravi Vishwakarma"  
published: 2024-07-16  
updated: 2024-07-16  
canonical: https://www.mindstick.com/forum/160927/sql-query-to-get-distinct-values-from-a-column-in-sql-server  
category: "SQL Server"  
tags: ["database", "sql server", "sql server 2008", "sql server 2012", "sql server 2022"]  
reading_time: 2 minutes  

---

# SQL Query to Get Distinct Values from a Column in SQL Server

I need a [query](https://www.mindstick.com/blog/202/sub-query-in-sqlserver) to get [distinct](https://www.mindstick.com/forum/159558/why-c-sharp-linq-distinct-doesn-t-work) [values](https://www.mindstick.com/forum/327/sum-textbox-values) from the `City` [column](https://www.mindstick.com/forum/33860/how-to-calculate-column-summary-in-sql-server) in the `Customers` table. Any [ideas](https://www.mindstick.com/articles/43878/making-the-best-use-of-the-options-trade-ideas)?

## Replies

### Reply by Ravi Vishwakarma

To get distinct values from a column in SQL Server, you can use the `SELECT DISTINCT` statement. This query will return all unique values from the specified column.

## Here’s the basic syntax:

```plaintext
SELECT DISTINCT column_name
FROM table_name;
```

## Example

Assume you have a table called `Customers` and you want to get all distinct values from the `City` column:

```plaintext
SELECT DISTINCT City
FROM Customers;
```

This query will return a list of unique cities from the `City` column in the `Customers` table.

#### Multiple Columns

If you want to get distinct combinations of values from multiple columns, you can include multiple columns in the `SELECT` statement:

```plaintext
SELECT DISTINCT column1, column2
FROM table_name;
```

For example, to get distinct combinations of `City` and `Country` from the `Customers` table:

```plaintext
SELECT DISTINCT City, Country
FROM Customers;
```

#### Ordering the Results

You can also order the distinct values using the `ORDER BY` clause:

```plaintext
SELECT DISTINCT City
FROM Customers
ORDER BY City;
```

This query will return the distinct cities in alphabetical order.


---

Original Source: https://www.mindstick.com/forum/160927/sql-query-to-get-distinct-values-from-a-column-in-sql-server

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
