0

i m using SQL 2008 R2

i got duplicate value from my join table: Join Table

SELECT *
FROM LETTRE_VOIT 
 LEFT JOIN FAWEB_CLIENT ON FAWEB_CLIENT.CODE_CLIENT = LETTRE_VOIT.CODE_CLIENT
 LEFT  JOIN ORDRE ON ORDRE.CODE_DEST = LETTRE_VOIT.CODE_DEST AND ORDRE.CODE_CLIENT = LETTRE_VOIT.CODE_CLIENT
   AND ORDRE.DATE_CLOTUR = LETTRE_VOIT.DATE_CLOTURE
WHERE  LETTRE_VOIT.NO_ORDRE IN ('5530','5533')

as you can see on image i got double value of 5530 and 5533.

my table FAWEB_CLIENT with ID Code_Client
table LETTRE_VOIT with ID NOID and NO_ORDRE
table ORDRE with ID NO_ORDRE and NO_CLIENT

i can not use DISTINCT: Distinct error message: The text data type can not be selected as DISTINCT because it is not comparable

4

1 回答 1

1

我怀疑问题是您的联接不正确。我的怀疑是您缺少以下连接条件Letter_Voit.No_Ordre

SELECT *
FROM LETTRE_VOIT 
 LEFT JOIN FAWEB_CLIENT ON FAWEB_CLIENT.CODE_CLIENT = LETTRE_VOIT.CODE_CLIENT
 LEFT  JOIN ORDRE ON ORDRE.CODE_DEST = LETTRE_VOIT.CODE_DEST AND ORDRE.CODE_CLIENT = LETTRE_VOIT.CODE_CLIENT
   AND ORDRE.DATE_CLOTUR = LETTRE_VOIT.DATE_CLOTURE and
   LETTRE_VOIT.No_ORDRE = Order.No_ORDRE
WHERE  LETTRE_VOIT.NO_ORDRE IN ('5530','5533')

您也许可以删除其他一些可能变得多余的连接条件。

于 2012-12-17T15:18:46.947 回答