在sql查询的输出中重复

时间:2017-10-18 10:27:30

标签: sql oracle

所以我在运行此查询后发现数据重复

 SELECT PRHA.REQUISITION_NUMBER  REQUISITION_NUMBER,
 PRLA.LINE_NUMBER  LINE_NUMBER,
 PRLA.QUANTITY  QUANTITY,
 PRLA.UNIT_PRICE  UNIT_PRICE,
 PRLA.UNIT_PRICE*PRLA.QUANTITY  AMOUNT,
 ESIV.ITEM_NUMBER  ITEM_NUMBER,
 ESIV.DESCRIPTION  DESCRIPTION,
 UOM.DESCRIPTION UNIT_OF_MEASURE

 FROM EGP_SYSTEM_ITEMS_VL ESIV,
 POR_REQUISITION_LINES_ALL PRLA,
 POR_REQUISITION_HEADERS_ALL PRHA,INV_UNITS_OF_MEASURE_VL  UOM

 WHERE PRHA.REQUISITION_HEADER_ID=PRLA.REQUISITION_HEADER_ID 
 AND PRLA.ITEM_ID=ESIV.INVENTORY_ITEM_ID 
 AND UOM.UOM_CODE = PRLA.UOM_CODE 
 AND PRHA.REQUISITION_NUMBER=:PR_NUMBER

如何解决?

1 个答案:

答案 0 :(得分:1)

如果整行是重复的,请使用DISTINCT

select DISTINCT -- removes duplicates iff the entire row matches another
       PRHA.REQUISITION_NUMBER  REQUISITION_NUMBER,
       PRLA.LINE_NUMBER  LINE_NUMBER,
       PRLA.QUANTITY  QUANTITY,
       PRLA.UNIT_PRICE  UNIT_PRICE,
       PRLA.UNIT_PRICE*PRLA.QUANTITY  AMOUNT,
       ESIV.ITEM_NUMBER  ITEM_NUMBER,
       ESIV.DESCRIPTION  DESCRIPTION,
       UOM.DESCRIPTION UNIT_OF_MEASURE

from  EGP_SYSTEM_ITEMS_VL ESIV
inner join POR_REQUISITION_LINES_ALL PRLA -- explicit join syntax for the 21st century
  on PRLA.ITEM_ID=ESIV.INVENTORY_ITEM_ID
inner join POR_REQUISITION_HEADERS_ALL PRHA
    on PRHA.REQUISITION_HEADER_ID=PRLA.REQUISITION_HEADER_ID
inner join INV_UNITS_OF_MEASURE_VL  UOM
    on UOM.UOM_CODE = PRLA.UOM_CODE

where PRHA.REQUISITION_NUMBER=:PR_NUMBER

如果只是某些行,即某些列,则从所有表中发布样本数据