Syntax error on join operation access SQL - sql

I'm trying to do some join operations in sql access but I keep on getting the join operation error. At first it was just the JOIN alone, but then I realized I had to add the INNER which I did but it didn't resolve the error.
Code below:
SELECT Formula.*, Ingred.[Europe Ban]
FROM [Ingred]
INNER JOIN Ingred ON Formula.[Ingredient] = Ingred.Ingredients;

Presumably, you want Formula in the FROM clause, not Ingred twice:
SELECT Formula.*, Ingred.[Europe Ban]
FROM Formula INNER JOIN
Ingred
ON Formula.[Ingredient] = Ingred.Ingredients;

Related

Access delete query with an inner join and subquery

I am trying to run a delete query that contains a subquery and an inner join and get the error
Query must have at least one destination field.
I have read elsewhere that you must use either of the following.
DISTINCTROW
WHERE EXISTS
But I still get the error message. I have read How to delete in MS Access when using JOIN's? and MS ACCESS delete query syntax combined with inner join problems but can't get it to work.
Here is my query.
DELETE FROM tblUp
WHERE NOT EXISTS (
SELECT tblUp.request_id,
tblUp.gid,
MAX(tblUp.savings_year) AS MaxOfsavings_year,
LAST(tblUp.savings_month) AS LastOfsavings_month
FROM tblUp
INNER JOIN tbl_w ON tblUp.request_id = tblW.id
GROUP BY tblUp.request_id,
tblUp.gid,
tblW.Cde
HAVING (((tblW.Cde)="ML"))
ORDER BY tblUp.request_id,
tblUp.gid,
MAX(tblUp.savings_year),
LAST(tblUp.savings_month)
)

Problem with creating view with multiple joins Postgres

I want to create a view that has 2 or more inner joins in Datagrip with Postgres. First of all, the following query has no problem executing:
select *
from student inner join participates t on student.matrnr = t.matrnr
inner join martin_classes mc on t.lvnr = mc.lvnr;
And this would be a sort of an intermediate result, so that's why I want to create it as a view. But when I try to execute this query:
create view martin_andAll as
select *
from student inner join participates t on student.matrnr = t.matrnr
inner join martin_classes mc on t.lvnr = mc.lvnr;
the following error occurs: [42701] ERROR: column "matrnr" specified more than once
an easy fix would be using the keyword USING instead of ON (condition)
but that only works if I'm having only one join.
So at the following query I get the exact same error as before:
create view martin_andAll as
select *
from student inner join participates t using (matrnr)
inner join martin_classes mc using (lvnr);
And just to be clear, this works just fine:
create view martin_andAll as
select *
from student inner join participates t using (matrnr);
So my question is, why doesn't it work with multiple joins and how can I overcome this?

Access SQL syntax error (missing operator) when query contains multiple JOINs

I'm trying to make an UPDATE query (using Access 2013) that calculates a value based on values stored in two separate linked tables. Here is the code I'm using:
UPDATE tblCreatures
INNER JOIN tblRole ON tblCreatures.Role = tblRole.RoleName
INNER JOIN tblRank ON tblCreatures.Rank = tblRank.RankName
SET tblCreatures.HP = ((tblRole.Level_0_HP + (tblCreatures.NominalLevel * tblRole.BonusHP)) * tblRank.HP_Multiplier);
This gives me a syntax error, saying
Syntax error (missing operator) in query expression "tblCreatures.Role = tblRole.RoleName INNER JOIN tblRank ON tblCreatures.Rank = tblRank.RankNam"
(and yes, it cuts off at RankNam, not RankName)
Testing things out, if I remove one of the inner joins (and thus all references to that table) then the update query works just fine, but if I put the other inner join back in, I continuously get this same syntax error. I don't understand why... I should be able to put two inner joins next to each other, shouldn't I?
Access SQL requires parentheses when a query contains multiple JOINs. If you build the query in Access' query designer it will look like this (reformatted for clarity):
UPDATE
(
tblCreatures
INNER JOIN
tblRole
ON tblCreatures.Role = tblRole.RoleName
)
INNER JOIN
tblRank
ON tblCreatures.Rank = tblRank.RankName
SET tblCreatures.HP = ((tblRole.Level_0_HP + (tblCreatures.NominalLevel * tblRole.BonusHP)) * tblRank.HP_Multiplier);

How to do an INNER JOIN in SSIS Excel Source component

SELECT [Sheet1$].ID,
CLng([Sheet1$].RecordID) AS RecordID,
[Sheet1$].col1,
[Sheet1$].col2,
[Sheet1$].col3,
[Sheet1$].col4,
[Sheet1$].col5,
[Sheet2$].Name
FROM [Sheet1$]
INNER JOIN [Sheet2$] ON
[Sheet1$].RecordID = [Sheet2$].RecordID
I have the above sample SQL Command in an SSIS Excel Source component. As seen in that query i'm doing an inner join on two excel sheets (Sheet1 and Sheet2) in the same workbook.
At this point the query executes well with out any errors.
However, i am not able to join on a 3rd sheet (Sheet3). When i try to inner join on sheet3, i get the following error message.
An OLE DB record is available. Source: "Microsoft Access Database Engine" Hresult: 0x80040E14 Description: "Syntax error (missing operator) in query expression '[Sheet1$].RecordID = [Sheet2$].ReportID
INNER JOIN [Sheet3$] ON
[Sheet1$].RecordID = [Sheet3$].RecordID'
So i am basically unable to do an inner join on two or more excel sheets. I'm only able to inner join on one excel sheet. The syntax i am using works in SQL Server, so i am wondering
if its supposed to work in a SSIS Excel source SQL Command as well since it seems to be using the Microsoft Access Database Engine.
Below is the query with the second join that is generating the above error:
SELECT [Sheet1$].ID,
CLng([Shee1$].RecordID) AS RecordID,
[Sheet1$].col1,
[Sheet1$].col2,
[Sheet1$].col3,
[Sheet1$].col4,
[Sheet1$].col5,
[Sheet2$].Name
FROM [Sheet1$]
INNER JOIN [Sheet2$] ON
[Sheet1$].RecordID = [Sheet2$].RecordID
INNER JOIN [Sheet3$] ON
[Sheet1$].RecordID = [Sheet3$].RecordID
Ok, i was doing it the wrong way. Microsoft access database engine used by the SSIS Excel Source component handles joins differently than SQL Server.
Apparently, you need to have n - 2 left parentheses after the from
clause and one right parenthesis before the start of each new join
clause except for the first, where n is the number of tables being
joined together.
The reason is that Access's join syntax supports joining only two
tables at a time, so if you need to join more than two you need to
enclose the extra ones in parentheses.
Quoted from Access-SQL: Inner Join with multiple tables
And confirmed at http://office.microsoft.com/en-001/access-help/inner-join-operation-HA001231487.aspx
So the below query now works
SELECT [Sheet1$].ID,
CLng([Shee1$].RecordID) AS RecordID,
[Sheet1$].col1,
[Sheet1$].col2,
[Sheet1$].col3,
[Sheet1$].col4,
[Sheet1$].col5,
[Sheet2$].Name
FROM (([Sheet1$])
INNER JOIN [Sheet2$] ON [Sheet1$].RecordID = [Sheet2$].RecordID)
INNER JOIN [Sheet3$] ON [Sheet1$].RecordID = [Sheet3$].RecordID
Lets try to cheat:
SELECT
CLng(x.RecordID) AS RecordID,
x.col1,
x.col2,
x.col3,
x.col4,
x.col5,
x.Name
FROM (
SELECT
[Sheet1$].RecordID,
[Sheet1$].col1,
[Sheet1$].col2,
[Sheet1$].col3,
[Sheet1$].col4,
[Sheet1$].col5,
[Sheet2$].Name
FROM [Sheet1$]
INNER JOIN [Sheet2$] ON
[Sheet1$].RecordID = [Sheet2$].RecordID
) as x
INNER JOIN [Sheet3$] ON
x.RecordID = [Sheet3$].RecordID

MS Access SQL Query - syntax error(missing operator) in query expression

I am trying to understand why my query(below) displays an error message in MS Access Sql query editor(sqlview) when I run it.
SELECT *
FROM tblUSPS
INNER JOIN tblProductUSPS
ON tblProductUSPS.[PRODUCTUSPS_USPS] = tblUSPS.[USPS_CODE]
INNER JOIN tblAttribute
ON tblUSPS.USPS_ID = tblAttribute.ATTRIBUTE_USPSID
As far as I know the script below if I delete either of the INNER join lines. For instance, this script runs with no errors
SELECT *
FROM tblUSPS
INNER JOIN tblProductUSPS
ON tblProductUSPS.[PRODUCTUSPS_USPS] = tblUSPS.[USPS_CODE]
And so does this
SELECT *
FROM tblUSPS
INNER JOIN tblAttribute ON tblUSPS.USPS_ID = tblAttribute.ATTRIBUTE_USPSID
But when I combine, something goes wrong and I am unable to find it so I would like some help identifying this please.
Access has strong opinions on parentheses.
SELECT *
FROM
(tblUSPS
INNER JOIN tblProductUSPS
ON tblProductUSPS.[PRODUCTUSPS_USPS] = tblUSPS.[USPS_CODE] )
INNER JOIN tblAttribute
ON tblUSPS.USPS_ID = tblAttribute.ATTRIBUTE_USPSID