After following this thread. I am getting an error as "Syntax Error in JOIN Operation"
Here Is my query
SELECT
StudentMaster.Student_id,
ExamDetails.Subject_id,
SubjectMaster.Subject_id
FROM
(StudentMaster
LEFT OUTER JOIN ExamDetails
ON StudentMaster.Student_id = ExamDetails.Student_id)
LEFT OUTER JOIN ExamDetails
ON SubjectMaster.subject_id = ExamDetails.Subject_id
Any help regarding this would be appreciable
Have you tried this one.
select s.Student_id,e.Subject_id,sub.Subject_id
from YourDatabaseName.SubjectMaster as sub
left outer join YourDatabaseName.ExamDetails as e
on sub.Subject_id=e.Subject_id
left outer join YourDatabaseName.StudentMaster as s
on s.Student_id=e.Student_id
group by s.Student_id
order by s.Student_id;
Related
I want to use inner join and right join statement.
This is the relation of my tables.
I'm trying but it says join statement is not supported.
Here's my code:
SELECT ProjectName, HoursWorked, FirstName, LastName
FROM (PROJECT AS P INNER JOIN ASSIGNMENT AS A ON P.ProjectID = A.ProjectID)
RIGHT JOIN EMPLOYEE AS E ON A.EmployeeNumber = E.EmployeeNumber
Someone use right join statement iteratively but it didnt' work for me.
Ms API says both left and right join can also use with inner join.
Why it didn't work?
Try using RIGHT JOIN instead of INNER JOIN in the sub select:
SELECT ProjectName, HoursWorked, FirstName, LastName
FROM (PROJECT AS P RIGHT JOIN ASSIGNMENT AS A ON P.ProjectID = A.ProjectID)
RIGHT JOIN EMPLOYEE AS E ON A.EmployeeNumber = E.EmployeeNumber
From the documentation:
A LEFT JOIN or a RIGHT JOIN may be nested inside an INNER JOIN, but an INNER JOIN may not be nested inside a LEFT JOIN or a RIGHT JOIN.
FROM (((Project
INNER JOIN MDS ON Project.PID=MDS.PID)
INNER JOIN PLocation ON Project.PID = PLocation.PID)
INNER JOIN Site ON PLocation.ACode = Site.ACode) AS [Prim]
LEFT JOIN ((Procurement INNER JOIN MagicT ON Procurement.PRNum = MagicT.PRNum)
INNER JOIN DO ON DO.DoNum = MagicT.DONum) AS [Prim2] ON Prim.PRNum = Prim2.PRNum
Hey guys. So the above from statement is giving me an error:
Syntax error in from clause
Funny thing is when I make the LEFT JOIN an INNER JOIN it runs fine, but sadly that isn't what I want. I read that I had to rename the inner queries and join them using their new names but unfortunately I do not think I did it properly.
Maybe this... using two inline views. but you should be able to do this with just ()'s in Access... however if you have same named columns in each of Prim/prim2 tables, this will present with errors you may have to spell out each of the column names needed in the inline views.
FROM (SELECT * FROM Project
INNER JOIN MDS ON Project.PID=MDS.PID
INNER JOIN PLocation ON Project.PID = PLocation.PID
INNER JOIN Site ON PLocation.ACode = Site.ACode) PRIM
LEFT JOIN (SELECT * from Procurement
INNER JOIN MagicT ON Procurement.PRNum = MagicT.PRNum
INNER JOIN DO ON DO.DoNum = MagicT.DONum) PRIM2
ON Prim.PRNUM = Prim2.PRNUM
--- maybe... in access the ()'s will handle the outer join but I don't know what table PRNUM is sourced from in (project, mds, plocation,site) so project is a guess...
FROM Project
INNER JOIN MDS ON Project.PID=MDS.PID
INNER JOIN PLocation ON Project.PID = PLocation.PID
INNER JOIN Site ON PLocation.ACode = Site.ACode
LEFT JOIN (SELECT * from Procurement
INNER JOIN MagicT ON Procurement.PRNum = MagicT.PRNum
INNER JOIN DO ON DO.DoNum = MagicT.DONum) PRIM2
ON Project.PRNUM = Prim2.PRNUM
You basically have
FROM Subquery1 LEFT JOIN Subquery2
but your subqueries don't have SELECT in them.
I think it should be:
FROM
(SELECT Prim.PRNum FROM
(((Project
INNER JOIN MDS ON Project.PID=MDS.PID)
INNER JOIN PLocation ON Project.PID = PLocation.PID)
INNER JOIN Site ON PLocation.ACode = Site.ACode)
AS [Prim])
LEFT JOIN
(SELECT Prim2.PRNum FROM
((Procurement INNER JOIN MagicT ON Procurement.PRNum = MagicT.PRNum)
INNER JOIN DO ON DO.DoNum = MagicT.DONum)
AS [Prim2])
ON Prim.PRNum = Prim2.PRNum
(edit: a little too late...)
I have also discovered one of my issues here, is that in Access, you can have a left or right join nested inside an inner join but CANNOT have an inner join inside a left or right join. Rewriting the query to not include these joins inside the inner joins has solved the issue.
Thank you for all the help.
When i run Following Query everything works well but the subQuery inside LEFT JOIN Fails and
SELECT inv.*,rc.*,po.*,cfd.*
FROM invoice_lineitem as inv
LEFT JOIN (
SELECT rc1.* FROM rentalcode as rc1 WHERE rc1.assetCategory=
(SELECT AssetCategory FROM assetmaster WHERE
AssetID=invoice_lineitem.asset_typeID)
AND invoice_lineitem.invoice_date between rc1.start_date
AND rc1.validity_date
) rc ON rc.email=inv.usernameID
LEFT OUTER JOIN purchase_order as po ON (po.PO_ID=inv.poNumber)
LEFT OUTER JOIN client_facility_data as cfd ON (cfd.email=inv.usernameID)
WHERE inv.contractID='2/1AS/10'
I get Error as
1054 - Unknown column 'invoice_lineitem.asset_typeID' in 'where
clause'
When i try the same query by just removing the all invoice_lineitem from SubQuery and placing it in WHERE(beside contractID) the query works but it acts like INNER JOIN Query i.e if Query Fails for any of the Where Clause i get No Data
SELECT inv.*,rc.*,po.*,cfd.*
FROM invoice_lineitem as inv
LEFT JOIN (
SELECT rc1.* FROM rentalcode as rc1
) rc ON rc.email=inv.usernameID
LEFT OUTER JOIN purchase_order as po ON (po.PO_ID=inv.poNumber)
LEFT OUTER JOIN client_facility_data as cfd ON (cfd.email=inv.usernameID)
WHERE inv.contractID='2/1AS/10' AND rc.assetCategory=(SELECT AssetCategory FROM assetmaster WHERE AssetID=inv.asset_typeID)
AND inv.invoice_date between rc.start_date and rc.validity_date
A subquery can't refer to tables in the outer query (and if it could, you would have to use the inv. alias).
Try this. I changed the subquery into another LEFT JOIN.
SELECT inv.*,rc.*,po.*,cfd.*
FROM invoice_lineitem as inv
LEFT JOIN rentalcode AS rc1
ON rc.email = inv.usernameID
AND inv.nvoice_date between rc1.start_date AND rc1.validity_date
LEFT JOIN assetmaster AS am
ON rc1.assetCategory = am.AssetCategory
AND inv.asset_typeID = am.AssetID
LEFT OUTER JOIN purchase_order as po ON (po.PO_ID=inv.poNumber)
LEFT OUTER JOIN client_facility_data as cfd ON (cfd.email=inv.usernameID)
WHERE inv.contractID='2/1AS/10'
I currently have the following Query
SELECT * FROM tbl_Cars c
INNER JOIN tbl_Car_Parts cp ON c.Id = cp.Id
INNER JOIN tbl_Car_Factory cf ON cp.Id = cf.Id
However I have now realised that there are some Ids which are in the Cars Table which are then not in the Car Parts table so these are being omitted from my results while I want them included. I tried changing my INNER JOIN to a LEFT OUTER JOIN but it made no difference in the result set I am returned?
Use LEFT OUTER JOIN in both of the joins.
SELECT * FROM tbl_Cars c
LEFT OUTER JOIN tbl_Car_Parts cp ON c.Id = cp.Id
LEFT OUTER JOIN tbl_Car_Factory cf ON cp.Id = cf.Id
Otherwise the second INNER JOIN will invalidate your first LEFT OUTER JOIN for those records that does not have ID (does not join) in the tbl_Car_Parts table.
After a LEFT OUTER JOIN you may be only use again INNER JOIN if the table you are joining is not related with the previous ones that are joined using the LEFT OUTER JOIN.
LEFT JOIN should have definitely solved your problem, Not sure why it didnt work.
Just to be safe I used Left join on both the tables...
SELECT * FROM tbl_Cars c
LEFT JOIN tbl_Car_Parts cp ON c.Id = cp.Id
LEFT JOIN tbl_Car_Factory cf ON cp.Id = cf.Id
Following query does not work in access.
SELECT Fields.FieldId, PrecisionSettings.DecimalPlaces
from Fields left outer join FieldGroup on Fields.FieldGroupId = FieldGroup.FieldGroupId
left outer join Category on FieldGroup.CategoryId = Category.CategoryId
left outer join PrecisionSettings on
Category.InputAttributesID=PrecisionSettings.AttributesID
It gives error as missing operator in query expression.
In Access you can only join two results at a time. To join more tables you need more parentheses:
SELECT
Fields.FieldId,
PrecisionSettings.DecimalPlaces
FROM
(
(
Fields
LEFT OUTER JOIN FieldGroup ON Fields.FieldGroupId = FieldGroup.FieldGroupId
)
LEFT OUTER JOIN Category ON FieldGroup.CategoryId = Category.CategoryId
)
LEFT OUTER JOIN PrecisionSettings ON Category.InputAttributesID = PrecisionSettings.AttributesID