2013-03-13 61 views
1

這是我的查詢,它顯示兩次具有相同信息的數據。我應該怎麼做纔會顯示一次數據?SQL Server 2008我該怎麼做才能讓它不顯示數據兩次?

SELECT 
     STUDENT.Stud_Num, STUDENT.Last_Name, STUDENT.First_Name, 
     STUDENT.Middle_Name, STUDENT.Program, CORRELATION.Corr_Code, 
     AVERAGE.Remarks, ACAD_QTR_LINK.Acad_Year, ACAD_QTR_LINK.Qtr, 
     COURSE.Course_Name, GRADES.Grades, GRADES.[No.OfTakes] 
    FROM 
     STUDENT 
inner join 
     AVERAGE on STUDENT.Stud_Num = AVERAGE.Stud_Num 
inner join 
     CORRELATION on AVERAGE.Corr_Code = CORRELATION.Corr_Code 
inner join 
     ACAD_QTR_LINK on AVERAGE.Acad_Qtr_ID = ACAD_QTR_LINK.Acad_Qtr_ID 
inner join 
     CORR_COUR_LINK on STUDENT.Stud_Num = CORR_COUR_LINK.Stud_Num 
inner join 
     COURSE on CORR_COUR_LINK.Course_Code = COURSE.Course_Code 
inner join 
     GRADES on CORR_COUR_LINK.Corr_Cour_ID = GRADES.Corr_Cour_ID 
where 
     STUDENT.Stud_Num like '%' and STUDENT.Program like '%' 
     and STUDENT.Last_Name like '%' and STUDENT.First_Name like '%' 
     and STUDENT.Middle_Name like '%' and ACAD_QTR_LINK.Acad_Year like '%' 
     and ACAD_QTR_LINK.Qtr like '%' 
     and COURSE.Course_Name like '%' and CORRELATION.Corr_Code like '%' 

結果輸出:

|StudNum|LName|FName|MName|Prog|CorrCode|Remarks|AcadYr|Qtr|CorName|Grades|No.OfTakes 
|2007131|Mendo|charisn|Chucka|ECE|ece12345|7.00000| '11-'12 |3rd|Mathema|89.000| 1 
|2007131|Mendo|charisn|Chucka|ECE|ece12345|7.00000| '11-'12 |3rd|Mathema|89.000| 1 
|2007131|Mendo|charisn|Chucka|ECE|ece12345|7.00000| '11-'12 |3rd|Electroni|65.000| 1 
|2007131|Mendo|charisn|Chucka|ECE|ece12345|7.00000| '11-'12 |3rd|Electroni|65.000| 1 
+0

請幫我:( – 2013-03-13 03:40:53

+0

如果你找到答案,請更新的問題鑑於你已經表明,它應該清楚地返回記錄什麼,我覺得可能是東西。還沒有提供,但我不知道還有什麼要問的。 – TEEKAY 2013-03-13 15:46:46

回答

0

響應1 如果行完全相同添加不同的或你可以通過所有列組。

SELECT distinct STUDENT.Stud_Num, .... 

如果你也可以找出表使連接返回多行或引入附加條件來限制他們,也可能消除重複的行。

回覆2看到您的評論後。

SELECT STUDENT.Stud_Num, STUDENT.Last_Name, STUDENT.First_Name, STUDENT.Middle_Name, STUDENT.Program, CORRELATION.Corr_Code, 
AVERAGE.Remarks, ACAD_QTR_LINK.Acad_Year, ACAD_QTR_LINK.Qtr, 
COURSE.Course_Name, GRADES.Grades, GRADES.[No.OfTakes] FROM STUDENT 
inner join AVERAGE on STUDENT.Stud_Num = AVERAGE.Stud_Num 
inner join CORRELATION on AVERAGE.Corr_Code = CORRELATION.Corr_Code 
inner join ACAD_QTR_LINK on AVERAGE.Acad_Qtr_ID = ACAD_QTR_LINK.Acad_Qtr_ID 
inner join CORR_COUR_LINK on STUDENT.Stud_Num = CORR_COUR_LINK.Stud_Num 
inner join COURSE on CORR_COUR_LINK.Course_Code = COURSE.Course_Code 
inner join GRADES on CORR_COUR_LINK.Corr_Cour_ID = GRADES.Corr_Cour_ID 
where STUDENT.Stud_Num like '%' and STUDENT.Program like '%' 
and STUDENT.Last_Name like '%' and STUDENT.First_Name like '%' 
and STUDENT.Middle_Name like '%' and ACAD_QTR_LINK.Acad_Year like '%' 
and ACAD_QTR_LINK.Qtr like '%' 
and COURSE.Course_Name like '%' and CORRELATION.Corr_Code like '%' 
group by STUDENT.Stud_Num, STUDENT.Last_Name, STUDENT.First_Name, STUDENT.Middle_Name, STUDENT.Program, CORRELATION.Corr_Code, 
AVERAGE.Remarks, ACAD_QTR_LINK.Acad_Year, ACAD_QTR_LINK.Qtr, 
COURSE.Course_Name, GRADES.Grades, GRADES.[No.OfTakes] 

工作小提琴 - http://sqlfiddle.com/#!3/2f42e/5

+0

先生,我也做到了這一點,仍然沒有工作 – 2013-03-13 02:53:20

+0

我不知道我將如何分組這我仍然不知道如何使用「 group by「與多個內部聯接 – 2013-03-13 02:55:10

+0

你的重複行是否相同?如果他們不是這兩個都不會回答你的問題我相信。 – TEEKAY 2013-03-13 02:58:04

相關問題