0

I have a table in my sql that have names and cities for example.

I want to make a Select Command that get all the cities and remove from the result the duplicates.

for the select i am using:

        string citiesSelect = "SELECT [city] FROM [people] ORDER BY [city]";
        CitiesDataSource.SelectCommand = citiesSelect;
        CitiesDataSource.Select(DataSourceSelectArguments.Empty);
        DropDownList2.DataSourceID = CitiesDataSource.ID;
1
  • you can either go for distinct or with group by option.... Commented Feb 8, 2012 at 13:40

3 Answers 3

4

use DISTINCT.

 string citiesSelect = "SELECT DISTINCT [city] FROM [people] ORDER BY [city]";
        CitiesDataSource.SelectCommand = citiesSelect;
        CitiesDataSource.Select(DataSourceSelectArguments.Empty);
        DropDownList2.DataSourceID = CitiesDataSource.ID;
Sign up to request clarification or add additional context in comments.

Comments

0

Consider the following line:

string citiesSelect = "SELECT DISTINCT [city] FROM [people] ORDER BY [city]";

Comments

0

Try this query:

SELECT DISTINCT [city] FROM [people] ORDER BY [city]

The documentation for DISTINCT can be found here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.