我有3张桌子:cc_claim
,cc_exposure
,cc_new
我试图通过claimID
从cc_claim
中选择claimNumber
,然后使用ID
从exposureID
表中检索cc_exposure
。最后我想从cc_new
表中选择具有exposureID
的列。到目前为止,这是我的代码:
SELECT cc_claim.ID as test
FROM cc_claim
where ClaimNumber ='19D1000011'
JOIN (cc_exposure where AssignedUserID = test)
我不确定我是否在正确的轨道上......新来的sql。
我想这可能是你想到的:
SELECT c.ID AS test
FROM cc_claim c
INNER JOIN cc_exposure ex
ON c.ID = ex.AssignedUserID
WHERE c.ClaimNumber = '19D1000011';
请注意,JOIN
总是在FROM
之后,在WHERE
条款之前。
你需要在匹配的ID上加入表来获得你需要的东西。
SELECT cc_claim.ID as test,new.exposureId
FROM cc_claim c
Inner JOIN cc_exposure ex
ON c.ID = ex.AssignedUserID
Inner JOIN cc_new new
ON ex.exposureId=new.exposureID
where c.ClaimNumber ='19D1000011'