I am new to MYSQL, and unable to resolve or even with so many answers on this forum, unable to identiy the error in this statement. I am using MYSQL database.
I have 2 tables: Ratemaster and rates, in which a customer can have 1 product with different rates. Because of this, there is a duplication of customer and product fields, only the rate field changes. Now Table Ratemaster has all the fields : id, Customer code, Product, Rate, user whereas Table Rates has only: id, cust code, Rate, user. - user field is for checking session_user.
Now Table Ratemaster has 3 records with all field values being same except Rate field empty.
Table Rates has different rates.
I want to have all rates to be updated in Ratemaster from Rates table. I am unable to do this with UPDATE
and LIMIT
mysql command, it is giving error as:
Incorrect usage of UPDATE and LIMIT
UPDATE Ratemaster, Rates
SET Ratemaster.Rate=Rates.Rate
WHERE Ratemaster.user=Rates.user
LIMIT 1
Read article about How to use ORDER BY and LIMIT on multi-table updates in MySQL
Usually you can use
LIMIT
andORDER
in yourUPDATE
statements, but in your case not, as written in the MySQL Documentation 12.2.10. UPDATE Syntax:Try the following:
The problem is that LIMIT is only to be used with SELECT statements, as it limits the number of rows returned by the query.
From: http://dev.mysql.com/doc/refman/5.5/en/select.html
Salam You can use this method and work properly !