Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i got this error

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from Loan where Loan.Loan_number = Borrower.Loan_number and Borrower.customer_na' at line 3


What I have tried:

<pre>import mysql.connector

connection = mysql.connector.connect(
host = "bankdata.csgjnxtaedo3.us-east-1.rds.amazonaws.com",
user="admin",
password="Admin1234",
database="cse4020_1")

cursor = connection.cursor ()
Tablename = "Accounts" # give tablename here

cursor.execute(" drop trigger if exists try_to_keep_em")

qrystr = ("""CREATE TRIGGER try_to_keep_em BEFORE UPDATE ON Tablename FOR EACH ROW 
          BEGIN 
              UPDATE Loan SET Loan.amount = Loan.amount - (0.15*Loan.amount) from Loan where Loan.Loan_number = Borrower.Loan_number and Borrower.customer_name = Depositor.customer_name and Depositor.account_number = Accounts.account_number 
          END;""")

cursor.execute(qrystr)

connection.commit()
connection.close()
Posted
Updated 17-Jun-22 20:16pm

1 solution

Get rid of the from Loan bit - it's not valid in an UPDATE query: SQL UPDATE Statement[^]

You should expect to get syntax errors every day, probably many times a day while you are coding - we all do regardless of how much experience we have! Sometimes, we misspell a variable, or a keyword; sometimes we forget to close a string or a code block. Sometimes the cat walks over your keyboard and types something really weird. Sometimes we just forget how many parameters a method call needs.

We all make mistakes.

And because we all do it, we all have to fix syntax errors - and it's a lot quicker to learn how and fix them yourself than to wait for someone else to fix them for you! So invest a little time in learning how to read error messages, and how to interpret your code as written in the light of what the compiler is telling you is wrong - it really is trying to be helpful!

So read this: How to Write Code to Solve a Problem, A Beginner's Guide Part 2: Syntax Errors[^] - it should help you next time you get a compilation error!
 
Share this answer
 
Comments
Richard Deeming 20-Jun-22 5:52am    
It depends on the DBMS - for example, in MS SQL Server:
UPDATE (Transact-SQL) - SQL Server | Microsoft Docs[^]

I suspect it's more to do with the fact that the WHERE clause references tables which aren't mentioned anywhere else in the query.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900