runoobdb# select * from COMPANY;
id | name | age | address | salary
----+-------+-----+-----------+--------1|Paul|32|California|200002|Allen|25|Texas|150003|Teddy|23|Norway|200004|Mark|25|Rich-Mond|650005|David|27|Texas|850006|Kim|22|South-Hall|450007|James|24|Houston|10000(7 rows)
让我们插入两条数据:
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);
现在数据如下:
id | name | age | address | salary
----+-------+-----+------------+--------1|Paul|32|California|200002|Allen|25|Texas|150003|Teddy|23|Norway|200004|Mark|25|Rich-Mond|650005|David|27|Texas|850006|Kim|22|South-Hall|450007|James|24|Houston|100008|Paul|32|California|200009|Allen|25|Texas|15000(9 rows)
接下来我们找出 COMPANY 表中的所有 NAME:
runoobdb=# SELECT name FROM COMPANY;
得到结果如下:
name
-------PaulAllenTeddyMarkDavidKimJamesPaulAllen(9 rows)
现在我们在 SELECT 语句中使用 DISTINCT 子句:
runoobdb=# SELECT DISTINCT name FROM COMPANY;
得到结果如下:
name
-------TeddyPaulMarkDavidAllenKimJames(7 rows)