Solved

How do I write a proper SQL INNER JOIN UPDATE?

Posted on 2009-04-08
5
181 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 60

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 60

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 60

Expert Comment

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

Good luck and happy coding!

Regards,
Kev
0

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

626 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