GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   A tiny mysql question (https://gfy.com/showthread.php?t=1217674)

MKA 09-19-2016 03:38 PM

A tiny mysql question
 
It's late and my brain simply stopped working. I want to sleep but need to finish this so who helps me going to bed....


I need a rather simple command to perform with MYSQL.
Its looks simple.

I have 2 tables in the same database.
table 1 is named= A
table 2 is named= B

In table 1 we have a column called "views"
In table 2 we have a column called "enabled"

Basically. If enabled = 0 then views should be updated to 0

I tried something like this
UPDATE content_views
SET views = 0 ,
WHERE CONTENT.ENABLED = 0

which obviously did not worked.

myleene 09-19-2016 05:32 PM

You're missing the "INNER JOIN" and the "ON":
MySQL - Join and Update Values From Another Table

nightslit 09-20-2016 01:58 AM

UPDATE content_views
SET views = 0
WHERE CONTENT.ENABLED = 0
LEFT JOIN content ON content_views.shared_column_name = content.shared_column_name

Something like this

MKA 09-20-2016 03:11 AM

Eventually, this did the trick..

UPDATE A AS t1
INNER JOIN B AS t2
ON t1.content = t2.record_num
SET t1.views = 0
WHERE t2.enabled = 0;

It needed an extra value that was similar in both databases to get this working. (A.content=B.record_num)


All times are GMT -7. The time now is 12:32 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123