所以我有这4张桌子 基本上我有这个代码。
$sql_exp = "SELECT c.Branch
FROM dbo.users a
INNER JOIN dbo.FA_Laptop b
ON a.userID = b.UserID
INNER JOIN dbo.Branch c
ON a.BranchID = c.BranchID
WHERE b.fa_id = $faidf";
$rs = $conn->Execute($sql_exp);
if ($rs->EOF) {
echo "<br><br><tr><td><font size=2> Branch is missing</td>";
} else {
while (!$rs->EOF){
echo "<br><br><tr><td>".$rs->Fields("Branch")."</td>";
$rs->movenext();
}
}
$rs->Close();
我的select语句,它允许我打印用户(juan)的“分支”,其中fa_id = $ faidf。(例如$ faidf =“1”)
我接下来要做的是使用FAID = $ faidf(即“1”)打印Pedro的分支。虽然他们的fa_id不同,我可以使用laptop_id连接它吗?
答案 0 :(得分:1)
试试这个SQL
SELECT c.Branchname, a.employeename
FROM dbo.users a
INNER JOIN dbo.FA_Laptop b
ON a.userID = b.UserID
INNER JOIN dbo.Branch c
ON a.BranchID = c.BranchID
WHERE b.Laptop_id=
(SELECT x.laptop_id FROM FA_Laptop x
WHERE x.fa_id="$faidf");
你应该得到
branchname,employeename
1,juan
1,Pedro
那是你在找什么?