MySQL UPDATE query styntax error - mysql

I am trying to update a year column in MySQL with the following query:
UPDATE PUB.oa_inthed
SET PUB.oa_inthed.yearno ='2016'
WHERE PUB.oa_intnom.intid = 'XC352332'
but keep receiving this error:
[AnyDAC][Phys][ODBC][DirectData][ODBC Progress OpenEdge Wire Protocol driver][OPENEDGE]Syntax error in SQL statement at or about ".oa_inthes.yearno ='2016' WHERE PUB.oa" (10713)
Can someone point me in the right direction as to what is going wrong?
Thanks in advance

if oa_inthed is the table name then just specify it once and again table name in WHERE doesn't match as of UPDATE statement. Your query should look like
UPDATE PUB.oa_inthed
SET yearno ='2016'
WHERE PUB.oa_intnom.intid = 'XC352332'
^........... This should be oa_inthed

I think this is problem
UPDATE PUB.oa_inthed
SET PUB.oa_inthed.yearno ='2016'
WHERE PUB.oa_inthed.intid = 'XC352332'
oa_intnom = oa_inthed
in where clause..

Related

OPENQUERY SQL Server MYSQL UPDATE

I have to work on a linked server. My goal: Update an entire table in mysql server(version:8.0.21) via OPENQUERY in SQL Server(version 13.0.1742.0). I tried this but it generates an error Row cannot be located for updating. Some values may have been changed since it was last read and this one The rowset was using optimistic concurrency and the value of a column has been changed after the containing row was last fetched or resynchronized.
update linkedTable
set
linkedTable.id_parent=unlinkedTable.IdCat1,
linkedTable.code=unlinkedTable.CodeFamilleFAT,
linkedTable.niveau=unlinkedTable.NiveauCategorieFAT,
linkedTable.langue=unlinkedTable.CodeLangueFAT,
linkedTable.nom=unlinkedTable.LibelleCommercialFAT,
linkedTable.descriptionA=unlinkedTable.DescriptifCom1FAT,
linkedTable.vignette=null,
linkedTable.id_categorie=unlinkedTable.id
from openquery(NAMELINKEDSERVER, 'select id_categorie, id_parent, code, niveau, langue, nom, description as descriptionA, vignette from DatabaseMySQL.Table') as linkedTable
inner join DatabaseSQLserver.dbo.Table as unlinkedTable on unlinkedTable.Id = linkedTable.id_categorie
Then I tried this:
update linkedTable
set
linkedTable.id_parent=unlinkedTable.IdCat1,
linkedTable.code=unlinkedTable.CodeFamilleFAT,
linkedTable.niveau=unlinkedTable.NiveauCategorieFAT,
linkedTable.langue=unlinkedTable.CodeLangueFAT,
linkedTable.nom=unlinkedTable.LibelleCommercialFAT,
linkedTable.descriptionA=unlinkedTable.DescriptifCom1FAT,
linkedTable.vignette=null,
linkedTable.id_categorie=unlinkedTable.id
from openquery(NAMELINKEDSERVER, 'select id_categorie, id_parent, code, niveau, langue, nom, description as descriptionA, vignette from DatabaseMySQL.Table') as linkedTable
inner join DatabaseSQLserver.dbo.Table as unlinkedTable on unlinkedTable.Id = linkedTable.id_categorie
where linkedTable.id_categorie = 1
This work but only one row is updated. So I wrote a stored procedure to update each line but it took too much time.
Can someone explain why my first query didn't work (question1) and how I can reduce the time of my stored procedure (question2)?
I use while loop (count the number of id and update each id).
Thank you in advance.
Kind Regards.
I resolve the problem by checking some option on ODBC Driver in MySQL and reading some forum. I check this box.
enter image description here
This option allows to avoid the errors quoted previously. With this option, i can update multiple values without error on join or other request. Thank you Solarflare and "Another guy" (i lost the name) for correcting me (EDIT A POST). Have nice day both.

How to avoid MySQL Workbench error code: 1175 during this UPDATE *without* disabling "safe updates"

I have a particular MySQL UPDATE statement which does specify the required primary key in its WHERE clause and yet which still produces Error 1175 when run in MySQL Workbench.
I am perfectly aware of MySQL error code: 1175 during UPDATE in MySQL Workbench. My case appears to be the same as MySQL error code: 1175 during UPDATE (MySQL-Workbench vs. console). Like that questioner, I do not wish to disable MySQL-Workbench's "safe update/delete" option. That question failed to get a solution. I would like to try to get an actual solution.
SQL UPDATE statement:
-- update new columns' values from corresponding rows in `charges_arc`
UPDATE `charges`
INNER JOIN `charges_arc` ON `charges`.`ChargeID` = `charges_arc`.`ChargeID`
SET `charges`.`ChargeClearDate` = `charges_arc`.`ChargeClearDate`
WHERE `charges`.`ChargeID` = `charges_arc`.`ChargeID`;
ChargeID is indeed the Primary Key column in both charges and charges_arc tables.
This means that this statement does satisfy MySQL Workbench's https://dev.mysql.com/doc/workbench/en/workbench-faq.html#faq-workbench-delete-safe:
By default, Workbench is configured to not execute DELETE or UPDATE
queries that do not include a WHERE clause on a KEY column.
Is there a solution to rewrite this query such that Workbench does not Error 1175, and which does not require setting SET SQL_SAFE_UPDATES=0/changing Workbench's preferences?
Well, having played further, so far I have found that the following seems to keep Workbench happy:
-- update new columns' values from corresponding rows in `charges_arc`
UPDATE `charges`
INNER JOIN `charges_arc` ON `charges`.`ChargeID` = `charges_arc`.`ChargeID`
SET `charges`.`ChargeClearDate` = `charges_arc`.`ChargeClearDate`
WHERE `charges`.`ChargeID` = `charges_arc`.`ChargeID`
AND `charges`.`ChargeID` <> -9999
That's just adding AND charges.ChargeID <> -9999 to the condition. It hardly narrows the scope much(!), and it's pretty ugly(!). I can only guess that Workbench would like to "see some kind of literal test against the PK", so that you show it you have thought about the PK in a certain way! It does at least allow you to do the query without disabling "safe updates".
I will leave this open for a couple of days to see if someone can think of something neater.
For my own part, I have a lot of these kind of UPDATEs in a large upgrading script file, this looks so ugly to me that I may end up going for SET SQL_SAFE_UPDATES=0 over the whole file after all...
EDIT: In the end I decided it was so ugly having to add something like the extra AND clause above to these types of UPDATE ... JOIN ...s that I preferred to SET SQL_SAFE_UPDATES=0 around them, at least for clarity.
Using MySQL 5.6 and MySQLWorkbench 8, I received this error in the same circumstances. I was able to fix the error by qualifying the field name in the WHERE clause.
For example, this caused the 1175 error:
UPDATE `tReports`
SET
`Title` = Title,
`Descr` = Descr
WHERE `ID` = ID;
And this resolved it:
UPDATE `tReports`
SET
`Title` = Title,
`Descr` = Descr
WHERE `tReports`.`ID` = ID;

Update Case-Sensitive DB Field In Laravel 5.3 With Postgres

I am trying to update a database column field with raw SQL in laravel. It's important to mention that the update code was written to MySQL drive but now I use Postgres. The column name is dayID. So the update code is:
DB::update("update table set travel = ... WHERE dayID = {$this->dayID}");
I must use raw SQL because I make some updates to polygon types.
The problem is that laravel automatically transforms the dayID to dayid so I get an error:
column "dayid" does not exist
I tried to set a variable in order to use it in update query but it also failed with the same error:
$var = "dayID";
DB::update("update table set travel = ... WHERE ".$var." = {$this->dayID}");
How can I fix it?
Please try DB::table with update below:
DB::table('table_name')
->where('dayID', $this->dayID)
->update(['travel' => '...']);
Laravel document :
https://laravel.com/docs/5.3/queries#updates

Update a column on a table from a table on another schema MySql

I accidentally updated far more records than I should have with the wrong information. I have the correct information in another schema but I cannot figure out how to update the incorrect one.
I've tried something like -
Insert into schema1.table1 set columnName = (Select statement????) Where ?????
And then I get lost.
I've read around and tried a few answers out and I keep either getting a syntax error, or nothing happens.
Any help would be appreciated.
update schema1.table1
inner join schema2.table2
on schema1.table1.IDColumn = schema2.table2.IDColumn
set schema1.table1.column1 = schema2.table2.column2
This Worked for me

UPDATE query not functioning in MySQL 5.0

I'm not completely sure what I'm doing wrong here I've looked through again and again for incorrectly placed quotes but I cannot for the life of me get this UPDATE query code to work... and I've troubleshooted it down to the query itself and it gives an incorrect syntax error, yet I have no idea what is wrong with it as it is identical to the manual.
$change = mysql_query("UPDATE Images SET Group='$group' WHERE ID = '$imgid'") or
die(mysql_error());
you might need to do :
"UPDATE Images SET `Group`='$group' WHERE ID = '$imgid'"
as group is a keyword in MySQL .
Well... if the update does not work this might have two reasons. Either your syntax is wrong; this should result in MySQL throwing an error which should show up with your die(mysql_error()).
Or there is simply no record matching your WHERE-condition. To check if any record was updated at all you might want to take a look at mysql_affected_rows(). And you could run a SELECT-query on that table, using the same WHERE-condition.
try this ..
"UPDATE Images SET Group='".$group."' WHERE ID = ".$imgid