在简单连接查询中复制记录

时间:2016-02-25 12:07:56

标签: sql plsql

请参阅下面的代码和预期结果的图片

视图的新查询给出了同样错误的结果

            select VW_DAWN_FRIDAY.*, invoice_no  from VW_DAWN_FRIDAY
            inner join cl$invoices 
            on cl$invoices.project_id = VW_DAWN_FRIDAY.project_id

             SELECT DISTINCT VW_Learners_Train_Cost.learner_id,
             VW_Learners_Train_Cost.project_id,
             VW_Learners_Train_Cost.client_name,
             VW_Learners_Train_Cost.FIRST_NAME,
             VW_Learners_Train_Cost.LAST_NAME,
             VW_Learners_Train_Cost.quote_no,
             cl$invoices.total "Invoiced Amt incl VAT",
             cl$invoices.invoice_no
             FROM VW_Learners_Train_Cost
             INNER JOIN cl$invoices
             ON cl$invoices.project_id = VW_Learners_Train_Cost.PROJECT_ID
             AND cl$invoices.client_id = VW_Learners_Train_Cost.client_id

结果 Results

预期 Expected

1 个答案:

答案 0 :(得分:0)

我认为您的问题是您在第二个查询中加入了两次:

ON cl$invoices.project_id = VW_Learners_Train_Cost.PROJECT_ID
AND cl$invoices.client_id = VW_Learners_Train_Cost.client_id

假设两个查询都试图获得相同(良好,相似)的输出。