2014-10-24 6 views
0

그래서 저는 itemlookupcode을 쿼리 결과에 추가하고자합니다. itemlookupcode은 항목 테이블에 있지만 쿼리가 다른 테이블에 대한 것입니다. 두 테이블 모두 itemdescription을 가졌지 만 조인을하거나 왼쪽 조인을하면 중복이 발생합니다.sql 결과에 열을 추가하십시오.

select * 
from [RAPurchaseOrderTransfer] 
where QtyDifference <> 0 
and fromstoreid = 111 
and DateCreated >= dateadd(dd, -30, GETDATE()) 

나는 어떻게 결과에 item.lookupcode을 추가 할 수 있습니까?

+0

다른 테이블의 이름은 무엇입니까? –

+0

일대 다 관계가있는 경우이 테이블의 레코드를 반복 (중복)하게됩니다. –

답변

0

중복을 피하기 위해 중첩 된 선택을 수행하여 itemlookupcode를 가져올 수 있습니다. MySQL과

그것과 같을 것이다 (한도 1 만 1을 반환합니다) : SQL 서버와

(select i.itemlookupcode from item i where i.itemdescription = r.itemdescription limit 1) 

그것과 같을 것이다 :

: 예를 들어

(select top 1 i.itemlookupcode from item i where i.itemdescription = r.itemdescription) 

select 
r.*, 
(select top 1 i.itemlookupcode from item i where i.itemdescription = r.itemdescription) 
from [RAPurchaseOrderTransfer] r 
where r.QtyDifference <> 0 
and r.fromstoreid = 111 
and r.DateCreated >= dateadd(dd, -30, GETDATE()) 
+0

고맙습니다. :) – Brian

관련 문제