Oracle PL/SQL/Select Query/UNIQUE — различия между версиями

Материал из SQL эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 10:00, 26 мая 2010

UNIQUE / DISTINCT

 
SQL>
SQL> CREATE TABLE purchase (
  2       product_name  VARCHAR2(25),
  3       quantity      NUMBER(4,2),
  4       purchase_date DATE,
  5       salesperson   VARCHAR2(3)
  6       );
Table created.
SQL>
SQL> INSERT INTO purchase VALUES ("A",   1,  "14-JUL-03", "CA");
1 row created.
SQL> INSERT INTO purchase VALUES ("B",   75, "14-JUL-03", "BB");
1 row created.
SQL> INSERT INTO purchase VALUES ("C",   2,  "14-JUL-03", "GA");
1 row created.
SQL> INSERT INTO purchase VALUES ("D",   8,  "15-JUL-03", "GA");
1 row created.
SQL> INSERT INTO purchase VALUES ("A",   20, "15-JUL-03", "LB");
1 row created.
SQL> INSERT INTO purchase VALUES ("B",   2,  "16-JUL-03", "CA");
1 row created.
SQL> INSERT INTO purchase VALUES ("C",   25, "16-JUL-03", "LB");
1 row created.
SQL> INSERT INTO purchase VALUES ("D",   2,  "17-JUL-03", "BB");
1 row created.
SQL>
SQL> SELECT UNIQUE product_name
  2  FROM          purchase
  3  ORDER BY      product_name;
PRODUCT_NAME
-------------------------
A
B
C
D
4 rows selected.
SQL>
SQL> SELECT Distinct product_name
  2  FROM          purchase
  3  ORDER BY      product_name;
PRODUCT_NAME
-------------------------
A
B
C
D
4 rows selected.
SQL>
SQL>
SQL> DROP TABLE purchase;
Table dropped.
SQL>