在 PostgreSQL 中,DISTINCT 关键字与 SELECT 语句一起使用,用于去除重复记录,只获取唯一的记录。
我们平时在操作数据时,有可能出现一种情况,在一个表中有多个重复的记录,当提取这样的记录时,DISTINCT 关键字就显得特别有意义,它只获取唯一一次记录,而不是获取重复记录。
语法
用于去除重复记录的 DISTINCT 关键字的基本语法如下:
SELECT DISTINCT column1, column2,.....columnN
FROM table_name
WHERE [condition]
实例
创建 COMPANY 表(下载 COMPANY SQL 文件 ),数据内容如下:
http://m.douguo.com/recipe/amp/2902447
http://m.douguo.com/recipe/mip/2902447
http://m.douguo.com/recipe/amp/2902457
http://m.douguo.com/recipe/mip/2902457
http://m.douguo.com/recipe/amp/2902481
http://m.douguo.com/recipe/mip/2902481
http://m.douguo.com/recipe/amp/2902482
http://m.douguo.com/recipe/mip/2902482
http://m.douguo.com/recipe/amp/2902491
http://m.douguo.com/recipe/mip/2902491
http://m.douguo.com/recipe/amp/2902525
http://m.douguo.com/recipe/mip/2902525
http://m.douguo.com/recipe/amp/2902524
http://m.douguo.com/recipe/mip/2902524
http://m.douguo.com/recipe/amp/2902555
http://m.douguo.com/recipe/mip/2902555
http://m.douguo.com/recipe/amp/2902585
http://m.douguo.com/recipe/mip/2902585
http://m.douguo.com/recipe/amp/2902587
http://m.douguo.com/recipe/mip/2902587
http://m.douguo.com/recipe/amp/2902601
http://m.douguo.com/recipe/mip/2902601
http://m.douguo.com/recipe/amp/2902633
http://m.douguo.com/recipe/mip/2902633
http://m.douguo.com/recipe/amp/2902639
http://m.douguo.com/recipe/mip/2902639
http://m.douguo.com/recipe/amp/2902661
http://m.douguo.com/recipe/mip/2902661
http://m.douguo.com/recipe/amp/2902695
http://m.douguo.com/recipe/mip/2902695
http://m.douguo.com/recipe/amp/2902699
http://m.douguo.com/recipe/mip/2902699
http://m.douguo.com/recipe/amp/2902719
http://m.douguo.com/recipe/mip/2902719
http://m.douguo.com/recipe/amp/2902737
http://m.douguo.com/recipe/mip/2902737
http://m.douguo.com/recipe/amp/2902755
http://m.douguo.com/recipe/mip/2902755
http://m.douguo.com/recipe/amp/2902783
http://m.douguo.com/recipe/mip/2902783
http://m.douguo.com/recipe/amp/2902787
http://m.douguo.com/recipe/mip/2902787
http://m.douguo.com/recipe/amp/2903180
http://m.douguo.com/recipe/mip/2903180
http://m.douguo.com/recipe/amp/2903315
http://m.douguo.com/recipe/mip/2903315
http://m.douguo.com/recipe/amp/2903334
http://m.douguo.com/recipe/mip/2903334
http://m.douguo.com/recipe/amp/2903336
http://m.douguo.com/recipe/mip/2903336
http://m.douguo.com/recipe/amp/2903341
http://m.douguo.com/recipe/mip/2903341
http://m.douguo.com/recipe/amp/2904138
http://m.douguo.com/recipe/mip/2904138
http://m.douguo.com/recipe/amp/2904163
http://m.douguo.com/recipe/mip/2904163
http://m.douguo.com/recipe/amp/2904164
http://m.douguo.com/recipe/mip/2904164
http://m.douguo.com/recipe/amp/2904189
http://m.douguo.com/recipe/mip/2904189
http://m.douguo.com/recipe/amp/2904210
http://m.douguo.com/recipe/mip/2904210
http://m.douguo.com/recipe/amp/2904216
http://m.douguo.com/recipe/mip/2904216
http://m.douguo.com/recipe/amp/2904238
http://m.douguo.com/recipe/mip/2904238
http://m.douguo.com/recipe/amp/2904242
http://m.douguo.com/recipe/mip/2904242
http://m.douguo.com/recipe/amp/2904254
http://m.douguo.com/recipe/mip/2904254
http://m.douguo.com/recipe/amp/2904258
http://m.douguo.com/recipe/mip/2904258
http://m.douguo.com/recipe/amp/2904261
http://m.douguo.com/recipe/mip/2904261
http://m.douguo.com/recipe/amp/2904276
http://m.douguo.com/recipe/mip/2904276
http://m.douguo.com/recipe/amp/2904349
http://m.douguo.com/recipe/mip/2904349
http://m.douguo.com/recipe/amp/2904357
http://m.douguo.com/recipe/mip/2904357
http://m.douguo.com/recipe/amp/2904392
http://m.douguo.com/recipe/mip/2904392
http://m.douguo.com/recipe/amp/2904409
http://m.douguo.com/recipe/mip/2904409
http://m.douguo.com/recipe/amp/2904422
http://m.douguo.com/recipe/mip/2904422
http://m.douguo.com/recipe/amp/2904428
http://m.douguo.com/recipe/mip/2904428
http://m.douguo.com/recipe/amp/2904466
http://m.douguo.com/recipe/mip/2904466
http://m.douguo.com/recipe/amp/2904478
http://m.douguo.com/recipe/mip/2904478
http://m.douguo.com/recipe/amp/2904480
http://m.douguo.com/recipe/mip/2904480
http://m.douguo.com/recipe/amp/2904513
http://m.douguo.com/recipe/mip/2904513
http://m.douguo.com/recipe/amp/2904514
http://m.douguo.com/recipe/mip/2904514
http://m.douguo.com/recipe/amp/2904548
http://m.douguo.com/recipe/mip/2904548
http://m.douguo.com/recipe/amp/2904560
http://m.douguo.com/recipe/mip/2904560
http://m.douguo.com/recipe/amp/2904605
http://m.douguo.com/recipe/mip/2904605
http://m.douguo.com/recipe/amp/2904619
http://m.douguo.com/recipe/mip/2904619
http://m.douguo.com/recipe/amp/2904634
http://m.douguo.com/recipe/mip/2904634
http://m.douguo.com/recipe/amp/2904639
http://m.douguo.com/recipe/mip/2904639
http://m.douguo.com/recipe/amp/2904657
http://m.douguo.com/recipe/mip/2904657
http://m.douguo.com/recipe/amp/2904660
http://m.douguo.com/recipe/mip/2904660
http://m.douguo.com/recipe/amp/2904694
http://m.douguo.com/recipe/mip/2904694
http://m.douguo.com/recipe/amp/2904699
http://m.douguo.com/recipe/mip/2904699
http://m.douguo.com/recipe/amp/2904740
http://m.douguo.com/recipe/mip/2904740
http://m.douguo.com/recipe/amp/2904774
http://m.douguo.com/recipe/mip/2904774
http://m.douguo.com/recipe/amp/2904776
http://m.douguo.com/recipe/mip/2904776
http://m.douguo.com/recipe/amp/2904796
http://m.douguo.com/recipe/mip/2904796
http://m.douguo.com/recipe/amp/2904835
http://m.douguo.com/recipe/mip/2904835
http://m.douguo.com/recipe/amp/2904849
http://m.douguo.com/recipe/mip/2904849
http://m.douguo.com/recipe/amp/2904879
http://m.douguo.com/recipe/mip/2904879
http://m.douguo.com/recipe/amp/2904887
http://m.douguo.com/recipe/mip/2904887
http://m.douguo.com/recipe/amp/2904910
http://m.douguo.com/recipe/mip/2904910
http://m.douguo.com/recipe/amp/2904915
http://m.douguo.com/recipe/mip/2904915
http://m.douguo.com/recipe/amp/2904928
http://m.douguo.com/recipe/mip/2904928
http://m.douguo.com/recipe/amp/2904931
http://m.douguo.com/recipe/mip/2904931
http://m.douguo.com/recipe/amp/2904950
http://m.douguo.com/recipe/mip/2904950
http://m.douguo.com/recipe/amp/2904953
http://m.douguo.com/recipe/mip/2904953
http://m.douguo.com/recipe/amp/2904954
http://m.douguo.com/recipe/mip/2904954
http://m.douguo.com/recipe/amp/2904974
http://m.douguo.com/recipe/mip/2904974
http://m.douguo.com/recipe/amp/2904975
http://m.douguo.com/recipe/mip/2904975
http://m.douguo.com/recipe/amp/2905002
http://m.douguo.com/recipe/mip/2905002
http://m.douguo.com/recipe/amp/2905026
http://m.douguo.com/recipe/mip/2905026
http://m.douguo.com/recipe/amp/2905028
http://m.douguo.com/recipe/mip/2905028
http://m.douguo.com/recipe/amp/2905345
http://m.douguo.com/recipe/mip/2905345
http://m.douguo.com/recipe/amp/2905357
http://m.douguo.com/recipe/mip/2905357
http://m.douguo.com/recipe/amp/2905425
http://m.douguo.com/recipe/mip/2905425
http://m.douguo.com/recipe/amp/2905501
http://m.douguo.com/recipe/mip/2905501
http://m.douguo.com/recipe/amp/2905535
http://m.douguo.com/recipe/mip/2905535
http://m.douguo.com/recipe/amp/2905537
http://m.douguo.com/recipe/mip/2905537
http://m.douguo.com/recipe/amp/2905543
http://m.douguo.com/recipe/mip/2905543
http://m.douguo.com/recipe/amp/2905563
http://m.douguo.com/recipe/mip/2905563
http://m.douguo.com/recipe/amp/2905566
http://m.douguo.com/recipe/mip/2905566
http://m.douguo.com/recipe/amp/2905577
http://m.douguo.com/recipe/mip/2905577
http://m.douguo.com/recipe/amp/2905598
http://m.douguo.com/recipe/mip/2905598
http://m.douguo.com/recipe/amp/2905670
http://m.douguo.com/recipe/mip/2905670
http://m.douguo.com/recipe/amp/2905686
http://m.douguo.com/recipe/mip/2905686
http://m.douguo.com/recipe/amp/2905702
http://m.douguo.com/recipe/mip/2905702
http://m.douguo.com/recipe/amp/2905721
http://m.douguo.com/recipe/mip/2905721
http://m.douguo.com/recipe/amp/2905733
http://m.douguo.com/recipe/mip/2905733
http://m.douguo.com/recipe/amp/2905764
http://m.douguo.com/recipe/mip/2905764
http://m.douguo.com/recipe/amp/2905765
http://m.douguo.com/recipe/mip/2905765
http://m.douguo.com/recipe/amp/2905787
http://m.douguo.com/recipe/mip/2905787
http://m.douguo.com/recipe/amp/2905801
http://m.douguo.com/recipe/mip/2905801
http://m.douguo.com/recipe/amp/2905815
http://m.douguo.com/recipe/mip/2905815
http://m.douguo.com/recipe/amp/2905823
http://m.douguo.com/recipe/mip/2905823
http://m.douguo.com/recipe/amp/2905835
http://m.douguo.com/recipe/mip/2905835
http://m.douguo.com/recipe/amp/2905858
http://m.douguo.com/recipe/mip/2905858
http://m.douguo.com/recipe/amp/2905859
http://m.douguo.com/recipe/mip/2905859
http://m.douguo.com/recipe/amp/2905909
http://m.douguo.com/recipe/mip/2905909
http://m.douguo.com/recipe/amp/2906023
http://m.douguo.com/recipe/mip/2906023
http://m.douguo.com/recipe/amp/2906060
http://m.douguo.com/recipe/mip/2906060
http://m.douguo.com/recipe/amp/2906061
http://m.douguo.com/recipe/mip/2906061
http://m.douguo.com/recipe/amp/2906115
http://m.douguo.com/recipe/mip/2906115
http://m.douguo.com/recipe/amp/2902698
http://m.douguo.com/recipe/mip/2902698
http://m.douguo.com/recipe/amp/2902838
http://m.douguo.com/recipe/mip/2902838
http://m.douguo.com/recipe/amp/2902932
http://m.douguo.com/recipe/mip/2902932
http://m.douguo.com/recipe/amp/2902953
http://m.douguo.com/recipe/mip/2902953
http://m.douguo.com/recipe/amp/2903021
http://m.douguo.com/recipe/mip/2903021
http://m.douguo.com/recipe/amp/2903164
http://m.douguo.com/recipe/mip/2903164
http://m.douguo.com/recipe/amp/2903243
http://m.douguo.com/recipe/mip/2903243
http://m.douguo.com/recipe/amp/2903249
http://m.douguo.com/recipe/mip/2903249
http://m.douguo.com/recipe/amp/2903302
http://m.douguo.com/recipe/mip/2903302
http://m.douguo.com/recipe/amp/2903405
http://m.douguo.com/recipe/mip/2903405
http://m.douguo.com/recipe/amp/2903445
http://m.douguo.com/recipe/mip/2903445
http://m.douguo.com/recipe/amp/2903453
http://m.douguo.com/recipe/mip/2903453
http://m.douguo.com/recipe/amp/2903608
http://m.douguo.com/recipe/mip/2903608
http://m.douguo.com/recipe/amp/2903614
http://m.douguo.com/recipe/mip/2903614
http://m.douguo.com/recipe/amp/2903638
http://m.douguo.com/recipe/mip/2903638
http://m.douguo.com/recipe/amp/2903640
http://m.douguo.com/recipe/mip/2903640
http://m.douguo.com/recipe/amp/2903682
http://m.douguo.com/recipe/mip/2903682
http://m.douguo.com/recipe/amp/2903708
http://m.douguo.com/recipe/mip/2903708
http://m.douguo.com/recipe/amp/2903746
http://m.douguo.com/recipe/mip/2903746
http://m.douguo.com/recipe/amp/2903767
http://m.douguo.com/recipe/mip/2903767
http://m.douguo.com/recipe/amp/2903787
http://m.douguo.com/recipe/mip/2903787
http://m.douguo.com/recipe/amp/2903790
http://m.douguo.com/recipe/mip/2903790
http://m.douguo.com/recipe/amp/2903818
http://m.douguo.com/recipe/mip/2903818
http://m.douguo.com/recipe/amp/2903822
http://m.douguo.com/recipe/mip/2903822
http://m.douguo.com/recipe/amp/2903837
http://m.douguo.com/recipe/mip/2903837
http://m.douguo.com/recipe/amp/2903847
http://m.douguo.com/recipe/mip/2903847
http://m.douguo.com/recipe/amp/2903863
http://m.douguo.com/recipe/mip/2903863
http://m.douguo.com/recipe/amp/2903869
http://m.douguo.com/recipe/mip/2903869
http://m.douguo.com/recipe/amp/2903910
http://m.douguo.com/recipe/mip/2903910
http://m.douguo.com/recipe/amp/2903974
http://m.douguo.com/recipe/mip/2903974
http://m.douguo.com/recipe/amp/2903994
http://m.douguo.com/recipe/mip/2903994
http://m.douguo.com/recipe/amp/2904030
http://m.douguo.com/recipe/mip/2904030
http://m.douguo.com/recipe/amp/2904068
http://m.douguo.com/recipe/mip/2904068
http://m.douguo.com/recipe/amp/2904077
http://m.douguo.com/recipe/mip/2904077
http://m.douguo.com/recipe/amp/2904120
http://m.douguo.com/recipe/mip/2904120
http://m.douguo.com/recipe/amp/2904139
http://m.douguo.com/recipe/mip/2904139
http://m.douguo.com/recipe/amp/2904153
http://m.douguo.com/recipe/mip/2904153
http://m.douguo.com/recipe/amp/2904162
http://m.douguo.com/recipe/mip/2904162
http://m.douguo.com/recipe/amp/2904196
http://m.douguo.com/recipe/mip/2904196
http://m.douguo.com/recipe/amp/2904301
http://m.douguo.com/recipe/mip/2904301
http://m.douguo.com/recipe/amp/2904313
http://m.douguo.com/recipe/mip/2904313
http://m.douguo.com/recipe/amp/2904348
http://m.douguo.com/recipe/mip/2904348
http://m.douguo.com/recipe/amp/2904394
http://m.douguo.com/recipe/mip/2904394
http://m.douguo.com/recipe/amp/2904429
http://m.douguo.com/recipe/mip/2904429
http://m.douguo.com/recipe/amp/2904441
http://m.douguo.com/recipe/mip/2904441
http://m.douguo.com/recipe/amp/2904464
http://m.douguo.com/recipe/mip/2904464
http://m.douguo.com/recipe/amp/2904483
http://m.douguo.com/recipe/mip/2904483
http://m.douguo.com/recipe/amp/2904512
http://m.douguo.com/recipe/mip/2904512
http://m.douguo.com/recipe/amp/2904546
http://m.douguo.com/recipe/mip/2904546
http://m.douguo.com/recipe/amp/2904579
http://m.douguo.com/recipe/mip/2904579
http://m.douguo.com/recipe/amp/2904599
http://m.douguo.com/recipe/mip/2904599
http://m.douguo.com/recipe/amp/2904607
http://m.douguo.com/recipe/mip/2904607
http://m.douguo.com/recipe/amp/2904688
http://m.douguo.com/recipe/mip/2904688
http://m.douguo.com/recipe/amp/2904741
http://m.douguo.com/recipe/mip/2904741
http://m.douguo.com/recipe/amp/2904770
http://m.douguo.com/recipe/mip/2904770
http://m.douguo.com/recipe/amp/2904783
http://m.douguo.com/recipe/mip/2904783
http://m.douguo.com/recipe/amp/2904809
http://m.douguo.com/recipe/mip/2904809
http://m.douguo.com/recipe/amp/2904828
http://m.douguo.com/recipe/mip/2904828
http://m.douguo.com/recipe/amp/2904830
http://m.douguo.com/recipe/mip/2904830
http://m.douguo.com/recipe/amp/2904846
http://m.douguo.com/recipe/mip/2904846
http://m.douguo.com/recipe/amp/2904873
http://m.douguo.com/recipe/mip/2904873
http://m.douguo.com/recipe/amp/2904880
http://m.douguo.com/recipe/mip/2904880
http://m.douguo.com/recipe/amp/2904927
http://m.douguo.com/recipe/mip/2904927
http://m.douguo.com/recipe/amp/2904955
http://m.douguo.com/recipe/mip/2904955
http://m.douguo.com/recipe/amp/2905013
http://m.douguo.com/recipe/mip/2905013
http://m.douguo.com/recipe/amp/2905022
http://m.douguo.com/recipe/mip/2905022
http://m.douguo.com/recipe/amp/2905031
http://m.douguo.com/recipe/mip/2905031
http://m.douguo.com/recipe/amp/2905034
http://m.douguo.com/recipe/mip/2905034
http://m.douguo.com/recipe/amp/2905657
http://m.douguo.com/recipe/mip/2905657
http://m.douguo.com/recipe/amp/2905669
http://m.douguo.com/recipe/mip/2905669
http://m.douguo.com/recipe/amp/2905672
http://m.douguo.com/recipe/mip/2905672
http://m.douguo.com/recipe/amp/2905707
http://m.douguo.com/recipe/mip/2905707
http://m.douguo.com/recipe/amp/2905708
http://m.douguo.com/recipe/mip/2905708
http://m.douguo.com/recipe/amp/2905717
http://m.douguo.com/recipe/mip/2905717
http://m.douguo.com/recipe/amp/2905723
http://m.douguo.com/recipe/mip/2905723
http://m.douguo.com/recipe/amp/2905729
http://m.douguo.com/recipe/mip/2905729
http://m.douguo.com/recipe/amp/2905738
http://m.douguo.com/recipe/mip/2905738
http://m.douguo.com/recipe/amp/2905810
http://m.douguo.com/recipe/mip/2905810
http://m.douguo.com/recipe/amp/2905811
http://m.douguo.com/recipe/mip/2905811
http://m.douguo.com/recipe/amp/2905874
http://m.douguo.com/recipe/mip/2905874
http://m.douguo.com/recipe/amp/2905919
http://m.douguo.com/recipe/mip/2905919
http://m.douguo.com/recipe/amp/2905945
http://m.douguo.com/recipe/mip/2905945
http://m.douguo.com/recipe/amp/2905948
http://m.douguo.com/recipe/mip/2905948
http://m.douguo.com/recipe/amp/2905956
http://m.douguo.com/recipe/mip/2905956
http://m.douguo.com/recipe/amp/2905959
http://m.douguo.com/recipe/mip/2905959
http://m.douguo.com/recipe/amp/2905964
http://m.douguo.com/recipe/mip/2905964
http://m.douguo.com/recipe/amp/2906042
http://m.douguo.com/recipe/mip/2906042