Solved

How do I write a proper SQL INNER JOIN UPDATE?

Posted on 2009-04-08
5
174 Views
Last Modified: 2012-05-06
The attached SQL statement isn't working.  Would someone talk a look at my syntax?

$q2 = "UPDATE documents AS d INNER JOIN document_tracks AS dt USING (doc_id) SET d.listens = '$listen_total' WHERE dt.doc_id = '$arr1[1]'";
0
Comment
Question by:tprofits
  • 3
  • 2
5 Comments
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 24097581
What is the database backend?  MySQL?  SQL Server?  What version?
0
 

Author Comment

by:tprofits
ID: 24097597
MySQL 5.
0
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 24097683
For MySQL that syntax looks correct.
UPDATE table1 t1 INNER JOIN table2 t2 USING(id)

SET t1.data = 'some value'

WHERE t2.somecolumn = 'some other value'

Open in new window

0
 

Author Closing Comment

by:tprofits
ID: 31568047
Now that the syntax is definitely correct, I moved on and found the problem in a different spot.  Thanks.
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 24098495
Glad I was able to help confirm.

Good luck and happy coding!

Regards,
Kev
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now