iT邦幫忙

0

MS-SQL INNER JOIN 兩個Table重複值問題 _已解決

  • 分享至 

  • xImage

各位前輩好小弟目前在SQL上面INNER JOIN了兩個Table
搜尋出來會有重複值的出現,想請問有沒有語法或判斷式可以把重複值過濾掉呢??
https://ithelp.ithome.com.tw/upload/images/20180328/20107444yZleXuq7ko.jpg

SELECT DISTINCT Antibiotic_Patient_infor.Pa_infor_ID, Antibiotic_Patient_infor.P_ID, Antibiotic_PDF_info.P_ID, Antibiotic_PDF_info.PDF_CreTime, Antibiotic_PDF_info.PDF_Path, Antibiotic_Drog_info.Certification 
FROM Antibiotic_Patient_infor 
INNER JOIN Antibiotic_PDF_info 
ON Antibiotic_Patient_infor.P_ID = Antibiotic_PDF_info.P_ID 
INNER JOIN Antibiotic_Drog_info 
ON Antibiotic_Patient_infor.P_ID = Antibiotic_Drog_info.P_ID 
WHERE Antibiotic_Patient_infor.P_ID 
LIKE '32492'
OR  Antibiotic_Patient_infor.P_Name 
LIKE '32492'
ORDER BY Antibiotic_PDF_info.PDF_CreTime DESC;
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
暐翰
iT邦大師 1 級 ‧ 2018-03-28 15:12:46
最佳解答

select去掉Antibiotic_Drog_info.Certification

SELECT DISTINCT Antibiotic_Patient_infor.Pa_infor_ID, Antibiotic_Patient_infor.P_ID, Antibiotic_PDF_info.P_ID, Antibiotic_PDF_info.PDF_CreTime, Antibiotic_PDF_info.PDF_Path
FROM Antibiotic_Patient_infor 
INNER JOIN Antibiotic_PDF_info 
ON Antibiotic_Patient_infor.P_ID = Antibiotic_PDF_info.P_ID 
INNER JOIN Antibiotic_Drog_info 
ON Antibiotic_Patient_infor.P_ID = Antibiotic_Drog_info.P_ID 
WHERE Antibiotic_Patient_infor.P_ID 
LIKE '32492'
OR  Antibiotic_Patient_infor.P_Name 
LIKE '32492'
ORDER BY Antibiotic_PDF_info.PDF_CreTime DESC;
看更多先前的回應...收起先前的回應...
小火車 iT邦新手 4 級 ‧ 2018-03-28 16:29:38 檢舉

謝謝大大的回覆,因為Antibiotic_Drog_info.Certification算是一個驗證的欄位必須顯示在頁面上,0(未被驗證)1(已驗證)如圖一樣
https://ithelp.ithome.com.tw/upload/images/20180328/20107444zLxigAU6KK.jpg
想請問大大還有其他方法可行嗎??
或是從GridView上面做轉換??

暐翰 iT邦大師 1 級 ‧ 2018-03-28 16:34:32 檢舉

重複的資料是指
Pa_infor_ID,P_ID,P_ID,PDF_CreTime,PDF_Path
這幾個欄位一樣?

小火車 iT邦新手 4 級 ‧ 2018-03-28 17:17:05 檢舉

對 Pa_infor_ID,P_ID,P_ID,PDF_CreTime,PDF_Path
這幾個欄位沒錯 我有找到GridView Merge Cll 的功能
不知道可不可行??

暐翰 iT邦大師 1 級 ‧ 2018-03-28 17:24:18 檢舉

我懂你意思了
用這個可以辦到How to merge cells with equal values in the GridView

小火車 iT邦新手 4 級 ‧ 2018-03-28 23:29:50 檢舉

感謝指點 我知道怎麼做了 謝謝!

我要發表回答

立即登入回答