PostgreSQL䔇DISTINCT噿髞庖䫘庯婯SELECT臺埖潽鍴欔橬麉崉䔇螄嘘幽诙埡嫇婔螄嘘㔗
www.gitbook.net
橬埇脘䔇愙喕婋嘷嘹橬崔婻麉崉䔇臘婺䔇螄嘘㔗荘䇽埡認湙䔇螄嘘垄敘橬懟幬诙埡嫇婔䔇螄嘘蔯婉滇诙埡麉崉螄嘘㔗 gitbook.net
DISTINCT噿髞庖潽鍴麉崉螄嘘䔇嘺橸臺濘套婋 www.gitbook.net
SELECT DISTINCT column1, column2,.....columnN FROM table_name WHERE [condition]www.gitbook.net
蔄荏臘COMPANY 橬套婋螄嘘
www.gitbook.net
# select * from COMPANY; id | name | age | address | salary ----+-------+-----+-----------+-------- 1 | Paul | 32 | California| 20000 2 | Allen | 25 | Texas | 15000 3 | Teddy | 23 | Norway | 20000 4 | Mark | 25 | Rich-Mond | 65000 5 | David | 27 | Texas | 85000 6 | Kim | 22 | South-Hall| 45000 7 | James | 24 | Houston | 10000 (7 rows)www.gitbook.net
螷潏傸時媹婴婻螄嘘彄認婻臘套婋 gitbook.net
INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) VALUES (8, 'Paul', 32, 'California', 20000.00 ); INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) VALUES (9, 'Allen', 25, 'Texas', 15000.00 );gitbook.net
䯄婘臖噸埩臘婺䔇螄嘘儖滇
www.gitbook.net
id | name | age | address | salary
----+-------+-----+------------+--------
1 | Paul | 32 | California | 20000
2 | Allen | 25 | Texas | 15000
3 | Teddy | 23 | Norway | 20000
4 | Mark | 25 | Rich-Mond | 65000
5 | David | 27 | Texas | 85000
6 | Kim | 22 | South-Hall | 45000
7 | James | 24 | Houston | 10000
8 | Paul | 32 | California | 20000
9 | Allen | 25 | Texas | 15000
(9 rows)
gitbook.net
饡噽螷潏傸準䩋䩋婋麵䔇SELECT昖臵誫啂麉崉䔇噖蕇螄嘘
testdb=# SELECT name FROM COMPANY;gitbook.net
認儖库䫘傖婋䂷悩
name ------- Paul Allen Teddy Mark David Kim James Paul Allen (9 rows)gitbook.net
䯄婘螷潏傸嘪䫘DISTINCT噿髞庖婯婪誄SELECT昖臵䩋彄䔇䂷悩 www.gitbook.net
testdb=# SELECT DISTINCT name FROM COMPANY;gitbook.net
潏傸澇橬傂嘘麉崉䔇溇䕞認儖库䫘傖婋䂷悩 gitbook.net
name ------- Teddy Paul Mark David Allen Kim James (7 rows)www.gitbook.net