473,698 Members | 2,156 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question about UPDATE and LEFT JOIN

Hi, I hope this is the right place to post, but, I am having a problem with
an UPDATE command and a LEFT JOIN, I am using something like:

UPDATE table_a LEFT JOIN table_b ON table_a.field1= table_b.field1 SET
table_b.field6= '1' WHERE table_a.field2= '1';

Something along those lines. Anyway, from what I can see on various web
sites, documentation, etc, I think it should work, however, I keep getting
this error...

#1064 - You have an error in your SQL syntax near 'LEFT JOIN table_b ON
table_a.field1 = table_b.field1 SET table_b.field6 = '1' ' at line 1

Any idea why this doesn't work? I tried rewriting it not to use the LEFT
JOIN, but, still received SQL syntax issues. I need to change a field in
table_b, but the only way I know which records to change is a field in
table_a.

Thanks.
Jul 23 '05 #1
2 2740
The above syntax worked when I tried it, what version of mysql are you
using?
mysql>select version();

http://dev.mysql.com/doc/mysql/en/update.html

Starting with MySQL 4.0.4, you can also perform UPDATE operations that
cover multiple tables:

UPDATE items,month SET items.price=mon th.price
WHERE items.id=month. id;

The example shows an inner join using the comma operator, but
multiple-table UPDATE statements can use any type of join allowed in
SELECT statements, such as LEFT JOIN.

Jul 23 '05 #2
Great, I am pretty sure that the version is not 4.0 or better, it is back in
the 3's... I was afraid that is what the problem would be...

"Bill Turczyn" <bt******@gmail .com> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.com...
The above syntax worked when I tried it, what version of mysql are you
using?
mysql>select version();

http://dev.mysql.com/doc/mysql/en/update.html

Starting with MySQL 4.0.4, you can also perform UPDATE operations that
cover multiple tables:

UPDATE items,month SET items.price=mon th.price
WHERE items.id=month. id;

The example shows an inner join using the comma operator, but
multiple-table UPDATE statements can use any type of join allowed in
SELECT statements, such as LEFT JOIN.

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2466
by: Narine | last post by:
Hi All, I need to write one complicated update statement and I'm looking at maybe finding a simpler way to do it. I have 2 tables: 1.Photo Table PhotoID FileName 1 111.jpg
2
2518
by: serge | last post by:
/* This is a long post. You can paste the whole message in the SQL Query Analyzer. I have a scenario where there are records with values pointing to wrong records and I need to fix them using an Update statement. I have a sample code to reproduce my problem. To simplify the scenario I am trying to use Order related tables to explain a little better the tables i have to work with.
5
15177
by: Harry Broomhall | last post by:
I wonder if anybody could give me a few pointers on a problem I face. I need to do an UPDATE on table A, from an effective left outer join on A and another table B. (This is trying to perform a number translation, where the items that need it are rare.) The following points *I think* are relevant: 1) The FROM clause in UPDATE should *only* show additional tables, otherwise I'll get an extra join I didn't want! (IMHO this could do
3
2283
by: dbuchanan | last post by:
Hello, (Windows forms - SQL Server) I fill my datagrid with a stored procedure that includes relationships to lookup tables so that users can see the values of the combobox selections rather than the key value that are stored in the table. It works well if the comboboxes are selected when the row is created.
2
2615
by: Sim Zacks | last post by:
The following query updated all the rows in the AssembliesBatch table, not just where batchID=5. There are 2 rows in the AssembliesBatch table with batch ID of 5 and I wanted to update both of them with their price, based on the data in the from clause. One row has 105 units and the other row has 2006 units. the active price in both rows is 6.6 and the pricedifferential is 0. My expectation is that the first row would be updated to 693...
1
7396
by: klalonde | last post by:
I was researching opinions on using cursors in stored procedures and found a thread http://www.thescripts.com/forum/thread143091.html discussing (generally) why not to use them. I took a cursor-based solution and took a stab at writing the equivalent to it as a set-based procedure. I then timed each process using Query Profiler by executing each 20 consecutive times in Query Analyzer (i.e. EXECUTE sp_CalculateRewards and EXECUTE...
1
4033
by: naveenchhibber | last post by:
Hi all pls tell me that the following statment is valid in oracle 9i or 10g.. update ws set received_by_facility = coalesce(rbf_ouk.organizational_unit_id, 0), assigned_to_facility = coalesce(atf_ouk.organizational_unit_id, 0), received_by_team = coalesce(rbt_ouk.organizational_unit_id, 0), assigned_to_team = coalesce(att_ouk.organizational_unit_id, 0)
3
3960
by: Michel Esber | last post by:
Hi all, DB2 V8 LUW FP 15 There is a table T (ID varchar (24), ABC timestamp). ID is PK. Our application needs to frequently update T with a new value for ABC. update T set ABC=? where ID = ?
1
4109
by: drahmani | last post by:
Can anyone tell me how to do this in Oracle? This is not the exact query but I wanted to simplify it a little. The problem I see is that the WHERE clause depends on the join which I cannot do in Oracle. ------ A update table1 t1 set t1.pdesc=t2.pdesc, t1.pcost=t3.pcost from table1 t1 left outer join table2 t2 on t1.name=t2.name left outer join table3 t3 on t2.product=t3.product where t1.site='MD' and t1.pdesc...
0
8603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8895
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7725
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2329
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.