Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select each record from table without repeating same record

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?

like image 381
Genjo Avatar asked Mar 06 '13 04:03

Genjo


People also ask

How do I select a record without duplicates in SQL?

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.

How do I avoid duplicates in select query?

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.

How do you prevent duplicate records in a table?

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).

How do I remove duplicate records from a select query?

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.


2 Answers

You have to use "DISTINCT" Keyword for getting distinct records you can use the following query,

"SELECT DISTINCT ID FROM "

like image 158
Sumit Mudkondwar Avatar answered Oct 12 '22 23:10

Sumit Mudkondwar


Use the distinct key word:

Select distinct id from TABLE;
like image 35
Marc Avatar answered Oct 12 '22 23:10

Marc