䯄婘嘉䘞饡釕 > 昄扞康 > PostgreSQL > PostgreSQL DISTINCT噿髞庖

PostgreSQL DISTINCT噿髞庖

準溊寘录桺䆹    䫌 悕垵幥 敘桄䬽橸    敟蓽庺渇

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昖臵誫啂麉崉䔇噖蕇螄嘘

www.gitbook.net

testdb=# SELECT name FROM COMPANY; 

gitbook.net

認儖库䫘傖婋䂷悩

www.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
橸䆍桺䆹鍴濘滯蘸蘘崡庺婺橸䆍寘录潡䚡臏
渵誯傂嘘嘵嚟䔇蘸蘘嘖臙媇媙濘滯庺崇優麉傡庺媿媘嚹携庥幹嘺䇔昍䘋
蘸蘘臙濘滯桺䆹蘸蘘躻悕垵幥 [http://www.gitbook.net]
橸桺湺鵻PostgreSQL DISTINCT噿髞庖
蘸蘘臙媺䘍寘桺鷆毖:http://www.gitbook.net/html/postgresql/2013/080567.html
婪婔䇺PostgreSQL HAVING床埖      婋婔䇺PostgreSQL亥溘溇傽