Should i use LEFT JOIN OR INNER JOIN or RIGHT JOIN for joining 3 different query into a single query

Course Queries Syllabus Queries 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Syllabus Queries related to Course Queries. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago


FIRST QUERY

$sql="SELECT distinct(syllabus.syllabusName) as subjectName,$cid as courseId, stud.batchId as batchId,course.courseId,course.syllabusId AS subjectID,course.unitId,stud.studentID as studentID  ,concat(stud.studentFirstName,' ',stud.studentLastName,' ',stud.studentRegistrationNumber) AS studentName
            FROM studentdetails  stud           
            INNER JOIN  `coursemapping` course 
            ON  stud.`courseId`=course.courseId
            INNER JOIN syllabus syllabus
            ON  course.syllabusId=syllabus.syllabusId 
            WHERE course.courseId ='$cid' AND course.syllabusId='$sid' AND stud.`batchId`='$bid'";  

SECOND QUERY

     $sql=" SELECT A.assignmentId, A.unitId, B.assignmentName, C.assignmentsBatchId AS batchId, C.courseId AS courseId,C.assignmentMappingId, D.studentId, concat( E.studentFirstName, ' ', E.studentLastName, ' ', E.studentRegistrationNumber ) AS studentName
            FROM studentdetails E
            INNER JOIN assignmentscompleted D ON E.studentId = D.studentId
            INNER JOIN assignmentsbatch C ON D.assignmentId = C.assignmentMappingId
            INNER JOIN assignments B ON D.assignmentId = B.assignmentId
            INNER JOIN assignmentsMapping A ON B.assignmentId = A.assignmentId
            WHERE A.assignmentId = '$sid'
            AND C.assignmentsBatchId = '$bid'
            AND C.courseId ='$cid'";

THIRD QUERY

    $sql    =   "SELECT distinct(C.syllabusName) as subjectName,B.maxAccadamicMarks as marksScored,B.academicMarks as maxMarks,B.marksPercentage as percentage  
                    FROM studentdetails A INNER JOIN marks B 
                    ON A.studentId=B.studentId AND A.courseId=B.courseId AND A.batchId=B.batchId 
                    INNER JOIN syllabus C 
                    ON  B.syllabusId=C.syllabusId WHERE A.studentUserName='$studentUserName'";

Here i com/tag/need">need to join all the three query in der">order to fetch the subject,student,accmarks,marks,percentage? how to join all this three query to single query

profilepic.png
manpreet 2 years ago


It looks like you would likely be able to merge the queries together quite easily as many are using common tables, but without a table structure I am just writing a quick and dirty mashup or the three queries you have provided. I am assuming that each of these queries retuns exactly what you need and nothing else.

I have altered the third query just so slightly to add in the studentID so that it can be properly joined with the other queries and also commented out redundant information in the d">second query.

select
    a.studentID as studentID,
    a.studentName as studentName,
    $cid as courseID,
    a.batchID as batchID,
    a.subjectID as subjectID,
    c.subjectName as subjectName,
    a.unitID as unitID,
    b.assignmentID as assignmentID,
    b.assignmentName as assignmentName,
    b.assignmentMappingID as assignmentMappingID,
    c.marksScored as marksScored,
    c.maxMarks as maxMarks,
    c.percentage as percentageMarks
from
(
    select 
        distinct(syllabus.syllabusName) as subjectName,
        $cid as courseID, 
        stud.batchId as batchID,
        course.courseID,
        course.syllabusId as subjectID,
        course.unitID,
        stud.studentID as studentID  ,
        concat(stud.studentFirstName,' ',stud.studentLastName,' ',stud.studentRegistrationNumber) AS studentName
    FROM 
        studentdetails  stud           
            INNER JOIN  `coursemapping` course 
                ON  stud.`courseId`=course.courseId
            INNER JOIN syllabus syllabus
                ON  course.syllabusId=syllabus.syllabusId 
    WHERE 
        course.courseId ='$cid' 
        AND course.syllabusId='$sid' 
        AND stud.`batchId`='$bid'
) a,
(
    SELECT 
        A.assignmentID, 
        A.unitID, 
        B.assignmentName, 
        C.assignmentsBatchId AS batchID, 
        C.courseId AS courseID,
        C.assignmentMappingID, 
        D.studentID, 
        --concat( E.studentFirstName, ' ', E.studentLastName, ' ', E.studentRegistrationNumber ) AS studentName
    FROM 
        studentdetails E
            INNER JOIN assignmentscompleted D 
                ON E.studentId = D.studentId
            INNER JOIN assignmentsbatch C 
                ON D.assignmentId = C.
                                                    
                                                    
0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.