Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Question about UPDATE and LEFT JOIN

 
   Database Help (Home) -> mySQL RSS
Next:  Merge Replication - Deleting Data  
Author Message
Scott Snella

External


Since: Feb 17, 2005
Posts: 2



(Msg. 1) Posted: Wed Feb 16, 2005 10:40 pm
Post subject: Question about UPDATE and LEFT JOIN
Archived from groups: mailing>database>mysql (more info?)

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.

 >> Stay informed about: Question about UPDATE and LEFT JOIN 
Back to top
Login to vote
bturczyn

External


Since: Jan 10, 2005
Posts: 7



(Msg. 2) Posted: Wed Feb 16, 2005 10:40 pm
Post subject: Re: Question about UPDATE and LEFT JOIN [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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=month.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.

 >> Stay informed about: Question about UPDATE and LEFT JOIN 
Back to top
Login to vote
Scott Snella

External


Since: Feb 17, 2005
Posts: 2



(Msg. 3) Posted: Thu Feb 17, 2005 12:41 am
Post subject: Re: Question about UPDATE and LEFT JOIN [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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" wrote in message

 > The above syntax worked when I tried it, what version of mysql are you
 > using?
 > mysql>select version();
 >
<font color=purple> > <a rel="nofollow" style='text-decoration: none;' href="http://dev.mysql.com/doc/mysql/en/update.html</font" target="_blank">http://dev.mysql.com/doc/mysql/en/update.html</font</a>>
 >
 > Starting with MySQL 4.0.4, you can also perform UPDATE operations that
 > cover multiple tables:
 >
 > UPDATE items,month SET items.price=month.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.
 >
 >> Stay informed about: Question about UPDATE and LEFT JOIN 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
2 x SUM(IF.. and 2x LEFT JOIN - Hi, Suppose I have a query like: SELECT products.name AS product, SUM(IF(stock.invoice=0,1,0)) AS in_stock, SUM(IF(shopcart.status=1,1,0)) AS reserved FROM products LEFT JOIN stock ON products.id=stock.product_id LEFT JOIN shopcart ON..

Join and limit the result question - Hi guys! I have a challenge that I hope you can help me with. I have three tables and I have exported them with some sample data and uploaded them here: http://server.arton.no/filesharing/SQL.zip Here is how the tables looks like:..

Best way to issue hundreds of inserts/updates??? - Using mysql 4.0.23- What is the best way to execute several (hundreds of) inserts and updates? Rather than issuing tons of individual inserts and updates, can I send the strings to a text file and then have mysql do them all?? IE : query.txt insert..

MySQL freezes, brings XP machine to a grinding halt - I've been using MySQL for a while for fairly light database development on my XP machine. Currently, I am just starting a new project and have experienced some big problems with MySQL today both on my office machine and at home where running a particular...

login as user 'root' but do not have root privlages and my.. - Hi gang: I'm experiencing a problem with MySQL -- I updated MySQL from version 4.1.0 to 4.1.10 and now when I login as root it doesn't show all the databases I should have access to, nor it doesn't recognize me being logged in as root (via..
   Database Help (Home) -> mySQL All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]