I have to run the following query in an access database:
SELECT School.Name, Student.Name, Grade.Grade
FROM( (`School` `School` LEFT JOIN `Student` `Student` ON `School`.`ID`=`Student`.`SchoolID`) INNER JOIN `Grade` `Grade` ON `Student`.`GradeID` = `Grade`.`ID`)
This gives me the error "Join expression not supported", but if I change the LEFT JOIN to INNER JOIN, it runs correctly. I think the way of using both these joins together on ms-access can have a different way. Can anyone pls tell me what is wrong in this query and/ or the reason that this is not supported.
Thanks
If they are at the same 'scope', the INNERS will always run, you can't conditionally have them run based on their order. You either have to use two LEFT joins and filter out the records you don't want, or alternatively use a View to scope the INNER JOIN.
The reason why LEFT JOIN and INNER JOIN results are the same is because all the records of table branch has at least one match on table user_mast . The main difference between INNER JOIN and LEFT JOIN is that LEFT JOIN still displays the records on the the LEFT side even if they have no match on the RIGHT side table.
You'll use INNER JOIN when you want to return only records having pair on both sides, and you'll use LEFT JOIN when you need all records from the “left” table, no matter if they have pair in the “right” table or not.
Remarks. Use a LEFT JOIN operation to create a left outer join. Left outer joins include all of the records from the first (left) of two tables, even if there are no matching values for records in the second (right) table. Use a RIGHT JOIN operation to create a right outer join.
I re-created your query in Access' query designer. The query worked with both joins as INNER, as you found. However, the query designer complained about "ambiguous outer join" when I tried to switch the first INNER JOIN to LEFT JOIN. LEFT for both joins works, as does INNER for both.
If you need LEFT for the first join and INNER for the second, you can move the tables from the second join into a subquery.
SELECT
School.[Name] AS school_name,
sub.[Name] AS student_name,
sub.Grade
FROM
School LEFT JOIN (
SELECT
Student.SchoolID,
Student.[Name],
Grade.Grade
FROM
Student INNER JOIN Grade
ON Student.GradeID = Grade.ID) AS sub
ON School.ID = sub.SchoolID;
Student
.GradeID
might be null, because you did a LEFT JOIN on Student, it might not exist for your second join.
So basically, whenever you do a LEFT JOIN, you cannot use any of those TABLES columns in future JOINS
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With