2011-08-08 2 views
0

안녕하세요 모두 내가 조건을 주어진 두 테이블에서 결과를 반환하기 위해 아래 쿼리를 달성하기 위해 노력하고 있어요. 예상 된 결과를 얻기 위해 올바른 쿼리를 넣으려면 어떻게해야합니까?같은 쿼리를 사용하여 두 테이블에 걸쳐 원하는 출력을 얻으려면

SELECT * FROM bw_tempclientdetails 
where companyname like '%fff%' 
not in (SELECT * FROM bw_clientallocation where companyname like '%fff%'); 

답변

1

사용 join <는

SELECT * 
    FROM bw_tempclientdetails bw_temp 
    LEFT JOIN bw_clientallocation bw_client 
    ON bw_temp.companyname = bw_client.companyname -- this is just an identifier or link between the tables 
WHERE bw_client.company LIKE '%fff%' 
    AND (bw_temp.companyname LIKE '%fff%' AND bw_client.company LIKE '%fff%'); 

이 희망 링크가 도움이 --follow. 행운을 빕니다.

+0

대단히 감사 합니다이 솔루션을 도와 –

+0

당신은 .. 당신의 작품에 행운을 빌어 요 .. :) – sailhenz

0
select t1.* from (
SELECT * FROM bw_tempclientdetails 
where companyname like '%fff%') as t1 
left join (SELECT * FROM bw_clientallocation where companyname like '%fff%') as t2 
on t1.companyname = t2.companyname 
where t2.companyname is null 
+0

귀하의 솔루션에 대한 고마워요 –

2
SELECT * FROM bw_tempclientdetails 
where companyname like '%fff%' and companyname 
not in (SELECT companyname FROM bw_clientallocation where companyname like '%fff%'); 
+0

이 솔루션은 매우 간단하고 짧게 보입니다. 고마워. –

+0

내가 도왔다면 기쁘다. 행운을 빕니다;) –

관련 문제