2011-06-25 46 views
0

我有兩個表:CardInfo和CardItems,所以每個CardInfo可能有多個CardItems。我需要一個SQL查詢來根據與CardInfo和CardItems表相關的一些條件從CardInfo獲取唯一記錄。如何從此表中檢索唯一記錄?

select c.* from CardInfo c, CardItems ci 
where c.cr_no = ci.cr_no and ci.wc_id = 'test' 

上面的查詢返回重複記錄。請提出解決方案。

回答

3

您可以刪除重複記錄與DISTINCT

select distinct c.* from CardInfo c, CardItems ci 
where c.cr_no = ci.cr_no and ci.wc_id = 'test' 
+0

夢幻般的想法! ;)(+1) –

0
select c.* from cardinfo as c innerjoin carditems as ci 
     on c.cr_no=ci.cr_no 
where ci.wc_id = 'test' 
+0

從carditems表中返回重複的行..我已經嘗試一個太.. –

+0

將ü請發表您的表數據的圖像。我會盡快覈實並回復給你。 – rahularyansharma

+0

只使用Distinct返回獨特的項目,檢查binil的答案 – niktrs