考虑以下三个 MySQL 表:
tweets urls tweets_urls
--------------------------- --------------------- ----------------
tweet_id text spam url_id host spam tweet_id url_id
--------------------------- --------------------- ----------------
1 I love cnn.com 0 16 cnn.com 0 1 16
2 fox.com is fuk 0 17 fox.com 1 2 17
3 love me! 0 4 16
4 blah cnn.com 0
5 nice fox.com 0
我想根据 tweets_urls 更新 tweets.spam,这意味着查询的输出应该是
tweets
---------------------------
tweet_id text spam
---------------------------
1 I love cnn.com 0 <-- tweets_urls tells me tweet_id 1 has url_id 16
2 fox.com is fuk 1 in it, and the urls-table tells me that url 16
3 love me! 0 is not spam (spam = 0)
4 blah cnn.com 0
5 nice fox.com 1
我希望我清楚自己。我一直在摆弄它,现在有这样的东西。我知道这不可能是正确的,但不知道如何重新开始。你?
UPDATE tweets SET spam = (
SELECT spam FROM urls
LEFT JOIN tweets_urls
WHERE urls.url_id = tweets_urls.url_id
)
任何帮助,将不胜感激 :-)