Yinks
Yinks

Reputation: 203

Select Inner join

enter image description here

so i have this 4 tables.
basically i have this code.

$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(); 

its my select statement where it enables me to print the "Branch" of the user(juan) where fa_id= $faidf.(for this example $faidf="1")

what i wanted to do next is to print the branch of Pedro by using the FAID=$faidf(which is "1"). though their fa_id is different could i connect it using laptop_id?

Upvotes: 0

Views: 195

Answers (1)

Jirawat Uttayaya
Jirawat Uttayaya

Reputation: 1302

Try this 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");  

You should get
branchname , employeename
1, juan
1, Pedro

Is that what you were looking for?

Upvotes: 1

Related Questions