Solved

How do I write a proper SQL INNER JOIN UPDATE?

Posted on 2009-04-08
5
176 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

805 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