質問

select t1.CardID,t2.Description,t5.BioData 
from db2.tblemployeeinfob t1
left join (db2.tbldepartments t2,db1.tblbiometrics t5)
on 
(t1.Department = t2.DepartmentID and
t1.CardID=t5.CardID
)

Return Result is 1420 | (NULL) | (NULL)

Expected Result is 1420 | DB2_Description_Value | DB1_BioData_value

if i remove cross database join, like remove db1 then query will work fine to join remaining two tables from same database.

if i do cross database join between db1 and db2, even table t2 from same database db2 is returning NULL.

Where is problem with my Query, so i can get value from both databases.

役に立ちましたか?

解決

You shouldn't be using a cross join here. You want two separate left joins:

SELECT t1.CardID, t2.Description, t5.BioData 
FROM db2.tblemployeeinfob AS t1
LEFT JOIN db2.tbldepartments AS t2 ON t1.Department = t2.DepartmentID
LEFT JOIN db1.tblbiometrics AS t5 ON t1.CardID = t5.CardID

他のヒント

            <?php
            include('../dbcon.php');
            include('../session.php');
            if (isset($_POST['delete_user'])){
            $id=$_POST['selector'];
            $class_id = $_POST['teacher_class_id'];
             $get_id=$_POST['get_id']; 
            $N = count($id);
            for($i=0; $i < $N; $i++)
            {
                $result = mysql_query("select * from files  where file_id = '$id[$i]' ")or die(mysql_error());
                while($row = mysql_fetch_array($result)){

                $fname = $row['fname'];
                $floc = $row['floc'];
                $fdesc = $row['fdesc'];
                $uploaded_by = $row['uploaded_by'];



                mysql_query("insert into files (floc,fdatein,fdesc,class_id,fname,uploaded_by) value('$floc',NOW(),'$fdesc','$class_id','$fname','$uploaded_by')")or die(mysql_error());


                }
            }
            ?>
            <script>
            window.location = 'downloadable.php<?php echo '?id='.$get_id; ?>';
            </script>
            <?php
            }

            if (isset($_POST['copy'])){
            $id=$_POST['selector'];

            $N = count($id);
            for($i=0; $i < $N; $i++)
            {
                $result = mysql_query("select * from files  where file_id = '$id[$i]' ")or die(mysql_error());
                while($row = mysql_fetch_array($result)){


                    $fname = $row['fname'];
                $floc = $row['floc'];
                $fdesc = $row['fdesc'];


                mysql_query("insert into teacher_backpack (floc,fdatein,fdesc,teacher_id,fname) value('$floc',NOW(),'$fdesc','$session_id','$fname')")or die(mysql_error());


                }
            }
            ?>
            <script>
            window.location = 'backpack.php';
            </script>
            <?php
            }
            ?>
            <?php

            if (isset($_POST['share'])){
            $id=$_POST['selector'];
            $teacher_id = $_POST['teacher_id1'];
            echo $teacher_id ; 
            $N = count($id);
            for($i=0; $i < $N; $i++)
            {
                $result = mysql_query("select * from files  where file_id = '$id[$i]' ")or die(mysql_error());
                while($row = mysql_fetch_array($result)){


                    $fname = $row['fname'];
                $floc = $row['floc'];
                $fdesc = $row['fdesc'];


                mysql_query("insert into teacher_shared (floc,fdatein,fdesc,teacher_id,fname,shared_teacher_id) value('$floc',NOW(),'$fdesc','$session_id','$fname','$teacher_id')")or die(mysql_error());


                }
            }
            ?>
            <script>
             window.location = 'tambah_share_file.php';
            </script>
            <?php
            }
            ?>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top