2013-09-24 215 views
0

請看以下查詢:SQL查詢返回重複行

SELECT a.reco_index_content_code,a.reco_index_content_name, a.reco_index_user_action_download_file, 
     CASE WHEN b.refdata_profession_passion_code LIKE '%-%' 
       THEN 'passion' 
       ELSE 'profession' 
      END AS passion_or_profession 
FROM tbl_reco_index_contents a 
INNER JOIN tbl_reference_databases b 
ON a.reco_index_content_code = b.refdata_content_code 
WHERE a.reco_index_user_action_installed = 1 and a.user_profile_number = 1 

查詢返回重複某些行。如果查詢不是自我解釋,我將不得不回覆更多細節。

任何幫助是非常讚賞的查詢

結果

AAY_AAYAB_FTD00028 PGA TOUR   /mnt/sdcard/googleCheckout/PGA TOUR.apk profession 
AAB_AABAE_FTD00071 PD Central   /mnt/sdcard/googleCheckout/Parkinson's Central.apk passion 
AAB_AABAE_FTD00071 PD Central   /mnt/sdcard/googleCheckout/Parkinson's Central.apk passion 
AAB_AABAE_FTD00072 com.diablo.psychiatry /mnt/sdcard/googleCheckout/Psychiatry-Neurology Pro.apk passion 
AAB_AABAE_FTD00072 com.diablo.psychiatry /mnt/sdcard/googleCheckout/Psychiatry-Neurology Pro.apk passion 
AAB_AABAA_FTD00074 Glasgow     /mnt/sdcard/googleCheckout/Glasgow Coma Scale Free.apk passion 
AAB_AABAA_FTD00073 FOUR Score   /mnt/sdcard/googleCheckout/FOUR score.apk passion 
AAB_AABAA_FTD00075 Qx Calculate    /mnt/sdcard/googleCheckout/Calculate by QxMD.apk passion 
+2

你能顯示你的查詢結果嗎? –

+0

用結果修改了我的問題 – user264953

+1

如果連接表中有多個匹配'refdata_content_code'的行,就會發生這種情況。 – Barmar

回答

1

根據您顯示的結果,一個簡單的DISTINCT將刪除,因爲在列所有值的重複是兩個相同行,

SELECT DISTINCT ..... 
+0

謝謝,它的工作。我會在接受更多測試後接受答案。再次感謝。 – user264953