Use Distinct to eliminate repetitions

xiaoxiao2021-03-06  59

The Distinct keyword can remove the repeated row from the results of the SELECT statement. If Distinct is not specified, all rows will be returned, including repeated rows. For example, if Distinct is not used when selecting all author IDs in Titleauthor, then the following line will be returned (including some repetitive rows):

USE PUBS

SELECT AU_ID

From titleauthor

The following is the result set:

AU_ID

-----------

172-32-1176

213-46-8915

213-46-8915

238-95-7766

267-41-2394

267-41-2394

274-80-9391

409-56-7008

427-17-2319

472-27-2349

486-29-1786

486-29-1786

648-92-1872

672-71-3249

712-45-1867

722-51-5454

724-80-9391

724-80-9391

756-30-7391

807-91-6654

846-92-7186

899-46-2035

899-46-2035

998-72-3567

998-72-3567

(25 row (s) affected)

After using Distinct, you can remove duplicate, and only the only author ID:

USE PUBS

SELECT DISTINCT AU_ID

From titleauthor

The following is the result set:

AU_ID

-----------

172-32-1176

213-46-8915

238-95-7766

267-41-2394

274-80-9391

409-56-7008

427-17-2319

472-27-2349

486-29-1786

648-92-1872

672-71-3249

712-45-1867

722-51-5454

724-80-9391

756-30-7391

807-91-6654

846-92-7186

899-46-2035

998-72-3567

(19 row (s) affected)

转载请注明原文地址:https://www.9cbs.com/read-82246.html

New Post(0)