2017-02-02 139 views
-7

可能有人請,給我如何加入以下兩個SELECT語句的一些建議:加入兩個SELECT語句

SELECT TOP 200 * 
FROM dbo.Creation_LimitsAndExclusions WITH (nolock) 
WHERE LeagueCodeID = 37 

select * 
from dbo.Creation_Markets with (nolock) 
where ClassID = 9 and IsParentMatch = 1 

在此先感謝。

+0

** [編輯] **你的問題Creation_LimitsAndExclusions採取行,並添加一些示例數據和預期基於該數據的輸出。 [**格式化文本**](http://stackoverflow.com/help/formatting)請,[無屏幕截圖](http://meta.stackoverflow.com/questions/285551/why-may-i-not -o -load-images-of-code-on-so-when-asking-question-285557#285557) –

+0

要建立連接,你必須使用表 – AlainIb

+0

中的列使用* Derived Tables *或* CommonTable表達式*? – dnoeth

回答

1

我不知道的關鍵是什麼,但如果鍵兩個表中是CreationID聯接是這樣的:

SELECT TOP 200 * 
FROM dbo.Creation_LimitsAndExclusions WITH (nolock) 
LEFT JOIN dbo.Creation_Markets ON Creation_LimitsAndExclusions.CreationID = Creation_Markets.CreationID 
WHERE Creation_LimitsAndExclusions.LeagueCodeID = 37 
    AND Creation_Markets.ClassID = 9 and Creation_Markets.IsParentMatch = 1 
0

也不知道,關鍵是什麼,但我想補充一個cm.creationId是不是在NULL條件where子句,以確保我們不從不匹配

SELECT TOP 200 * 
FROM dbo.Creation_LimitsAndExclusions cle WITH (nolock) 
LEFT JOIN dbo.Creation_Markets cm 
    ON cle.CreationID = cm.CreationID 
WHERE cle.LeagueCodeID = 37 
    AND cm.ClassID = 9 
    AND cm.IsParentMatch = 1 
    AND cm.creationID IS NOT NULL