How do I select each record without repeating the same record?
Example:
ID item
------ -------
ABC item 1
XXX item 2
AXA item 3
ABC item 4
XXX item 5
From the table above, I just want to select each record such as ABC, XXX and AXA without repeating it. How do I do so in MS SQL 2005?
If you want the query to return only unique rows, use the keyword DISTINCT after SELECT . DISTINCT can be used to fetch unique rows from one or more columns.
The SQL DISTINCT keyword, which we have already discussed is used in conjunction with the SELECT statement to eliminate all the duplicate records and by fetching only the unique records.
In the Navigation Pane, right-click the table that contains the field, and then click Design View. Select the field that you want to make sure has unique values. In the Field Properties pane at the bottom of the table design view, on the General tab, set the Indexed property to Yes (No duplicates).
The go to solution for removing duplicate rows from your result sets is to include the distinct keyword in your select statement. It tells the query engine to remove duplicates to produce a result set in which every row is unique.
You have to use "DISTINCT" Keyword for getting distinct records you can use the following query,
"SELECT DISTINCT ID FROM "
Use the distinct
key word:
Select distinct id from TABLE;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With