我有三张桌子tbA和tbB
TBA
TBB
TBC
现在我必须获取分配给tbA的所有BName
我试过像
SELECT
L.tbBId L.tbBName FROM tbB L
JOIN
tbC P ON P.tbAId = @AId;
请帮帮我!!!
答案 0 :(得分:1)
select tbAId,tbAName,tbBName
from tbA join tbC
on tbA.tbAId=tbC.tbAId
join tbB
on tbB.tbBId=tbC.tbBId
WHERE P.tbAId = @AId
答案 1 :(得分:1)
需要更改的更正
1。您没有用逗号分隔两列
L.tbBId L.tbBName
2。您尚未在查询中考虑过表格tbA&您将tbAId
放入查询
以下是更改后的查询。我想这会对你有帮助
SELECT
L.tbBId,
L.tbBName
FROM
tbB L
INNER JOIN
tbC P ON P.tbBId = L.tbBId
INNER JOIN
tbA A ON P.tbAId = A.tbAId
WHERE
P.tbAId = @AId;
答案 2 :(得分:0)
试试这个..
SELECT L.tbBId,
L.tbBName
FROM tbB L
JOIN tbC P
ON P.tbBId = L.tbBId
JOIN tbA A
ON P.tbAId = A.tbAId
WHERE P.tbAId = @AId;