Syntax error (missing operator) when using UPDATE with INNER JOIN - sql

I'm trying to execute this SQL query on an MS Access DB:
UPDATE WW_B
SET WW_B.WWtype_ID=1
INNER JOIN New_data
ON WW_B.StdNr = New_data.StdNr;
But I get the following error:
[Microsoft][ODBC Microsoft Access Driver]
Syntax error (missing operator) in expression 1 INNER JOIN New_data on WW_B.StdNr = New_data.StdNr.
I don't see where any operator is needed, since I don't use any parentheses or quotation marks.
I've also tried WWtype_ID='1' and WWtype_ID="1" and got the same error.
What am I doing wrong?

I was having the same problem and found this question while searching for an answer. Luckily I was able to find a solution while digging through some Access queries at work.
This is just another situation where MS Access does not play nice with standard SQL syntax.
The other answers are incorrect. You do not need a FROM clause, Access will just give you the same error message. Where you ran into the error was where you placed the JOIN. It seems intuitive that you would have FROM...JOIN... But this is MS Access where working with SQL is never intuitive.
In Access, UPDATE seems to take the place of FROM. Therefore, you add the JOIN statement to the end of the UPDATE clause.
UPDATE WW_B
INNER JOIN New_data
ON WW_B.StdNr = New_data.StdNr
SET WW_B.WWtype_ID=1;
You can also add a WHERE clause after the SET statement if desired.

You need a FROM clause when using an INNER JOIN on an UPDATE:
UPDATE WW_B
SET WW_B.WWtype_ID = 1
FROM WW_B
INNER JOIN New_data
on WW_B.StdNr = New_data.StdNr

You are missing the FROM clause
UPDATE WW_B SET WW_B.WWtype_ID=1 FROM <your table> INNER JOIN New_data on WW_B.StdNr = New_data.StdNr

Related

What is the difference between a JOIN and LEFT JOIN when running an UPDATE in Redshift?

This question is stemming from another question I asked here: Two similar UPDATE statements in Redshift, one throws an error but the other doesn't
This is not asking about the difference between a JOIN and a LEFT JOIN, I understand that.
Rather I am specifically asking about how Redshift works when running an UPDATE statement similar to this one:
UPDATE billing_temp
SET spotlink = sl.spotlink
FROM billing_temp AS bt
LEFT JOIN spot_link AS sl
ON bt.dupeid = sl.dupeid;
Which throws this error:
Error: Target table must be part of an equijoin predicate
And how it differs from running an UPDATE statement like this:
UPDATE public.billingcombined
SET revenue_type = r.revenue_type
FROM public.billingcombined AS b
JOIN public.revenuetype AS r
ON b.contract_number = r.contract_number;
Which does not throw the error.
I can see that the bad statement contains a LEFT JOIN while the good one uses a regular JOIN.
I want to understand what an equijoin predicate means in this situation and why the LEFT JOIN does not work.
Amazon Redshift SQL does not support Left, right, and full outer joins in the FROM clause of an UPDATE statement; they return this error:
ERROR: Target table must be part of an equijoin predicate
Reference:
Amazon Redshift - Update
Amazon Redshift - Update Examples

Stored Procudure SQL error in Node `mssql` package

I am trying to recreate a Sql Server stored procedure in my Node app, which uses the mssql npm package. Right now, when I try and run the following query, I get an incorrect SQL error:
UPDATE
dbo.C2980251
RIGHT JOIN CFRTR...dbo.UPR10301 ON dbo.C2980251.BACHNUMB = dbo.UPR10301.BACHNUMB
SET
dbo.C2980251.UPRBCHOR = dbo.UPR10301.uprbchor,
dbo.C2980251.BACHNUMB = dbo.UPR10301.bachnumb,
dbo.C2980251.TRU_TYPE_ID = "132"
WHERE
(((dbo.C2980251.BACHNUMB) Is Null))
The specific error is this:
Incorrect syntax near the keyword 'RIGHT'.
To clarify, CFRTR, refers to the db being targeted. All of the tables being used here are from the same db.
It's not clear to me what the error is here. How should this be written?
The correct syntax is:
UPDATE c
SET UPRBCHOR = u.uprbchor,
BACHNUMB = u.bachnumb,
TRU_TYPE_ID = 132
FROM dbo.C2980251 c LEFT JOIN
CFRTR.dbo.UPR10301 u
ON u.BACHNUMB = c.BACHNUMB
WHERE u.BACHNUMB Is Null
Notes:
SQL Server requires a separate FROM clause.
Table aliases make the query much easier to write and read.
A LEFT JOIN makes much more sense here than a RIGHT JOIN. The database cannot update records that don't exist.
u.uprbchor and u.bachnumb are going to be NULL because the WHERE clause only keeps rows with no matches.

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);

SQL/Excel/VBA - UPDATE query: 'Syntax Error (missing operator) in query expression'

I have very simple query that is not working and I get error:
'Syntax Error (missing operator) in query expression Tabela2.SALES2
FROM Tabela2'
Here is the code:
UPDATE Tabela1
SET Tabela1.SALES = Tabela2.SALES2
FROM Tabela2
WHERE Tabela1.ID = Tabela2.ID
I want to run this query from VBA/Excel on Acces database (2007). Others queries with e.g. SELECT are working fine, so the problem is only with the query. And I really don't know why it is not working.
An UPDATE query using FROM is possible in SQL Server, but not in MS Access. Use this instead:
UPDATE Tabela1 INNER JOIN Tabela2 ON Tabela1.ID = Tabela2.ID
SET Tabela1.Sales = [Tabela2].[Sales2];
UPDATE Tabela1
SET Tabela1.SALES = Tabela2.SALES2
FROM Tabela1,Tabela2
WHERE Tabela1.ID = Tabela2.ID
try this
UPDATE Tabela1
SET Tabela1.SALES = Tabela2.SALES2
FROM Tabela1
INNER JOIN Tabela2
WHERE Tabela1.ID = Tabela2.ID
Update TABLE2, TABLE1
SET TABLE2.SALES2 = TABLE1.SALES
WHERE TABLE2.ID=TABLE1.ID
hey friends try this 100% working. As per poonam FROM statement is not possible and its true but no need to inner join and make your query slow down.
This SQL Query will run on MS Access only.

Implementing "Except" SQL Operation in MS Access 2003

I think that I should explain my problem a little bit in detail. May be you can help me to solve it.
I want to save a resault of a query in a "Temporary" Table hence I tried to use this query:
SELECT *
INTO Temp_tbl
FROM (tb_KonzeptDaten LEFT JOIN tb_Fahrzeug ON tb_KonzeptDaten.Konzept = tb_Fahrzeug.ID) LEFT JOIN tb_MSG ON tb_Fahrzeug.Motor_SG = tb_MSG.ID
I got the error 3090 which says "Resultant table not allowed to have more than one AutoNumber field."
that was correct! in eac of these three table I have an autonumber field
then I've deceided to select all fields without these Autonumber fields and then I've found that we can do this job with SQL EXCEPT operator but unfortunatlly it seems that this operator doesn't work in MS Access 2003
then I tried to use SQL "NOT EXIST" operator:
SELECT *
FROM (tb_KonzeptDaten LEFT JOIN tb_Fahrzeug ON tb_KonzeptDaten.Konzept = tb_Fahrzeug.ID) LEFT JOIN tb_MSG ON tb_Fahrzeug.Motor_SG = tb_MSG.ID
WHERE NOT EXISTS(SELECT tb_KonzeptDaten.ID FROM tb_KonzeptDaten)
but I didn't get my desired answer
What do you mean? How can I solve this problem?