Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8213545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:09:19+00:00 2026-06-07T11:09:19+00:00

Consider the following three MySQL tables: tweets urls tweets_urls ————————— ——————— —————- tweet_id text

  • 0

Consider the following three MySQL tables:

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

I want to update tweets.spam by according to tweets_urls, meaning the output of the query should be

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

I hope I’m making myself clear. I have been fiddling with it and now have something like this. I know it cannot be correct, but have no idea on how to start over. Do you?

UPDATE tweets SET spam = (
  SELECT spam FROM urls
  LEFT JOIN tweets_urls
  WHERE urls.url_id = tweets_urls.url_id
)

Any help would be appreciated 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T11:09:20+00:00Added an answer on June 7, 2026 at 11:09 am

    For your given data, this query returns the result set…

    SELECT t.tweet_id
         , t.text
         , IFNULL(s.spam,t.spam) AS spam
      FROM tweets t
      LEFT
      JOIN ( SELECT tu.tweet_id, MAX(u.spam) AS spam
               FROM tweets_urls tu
               JOIN urls u ON u.url_id = tu.url_id
              WHERE u.spam = 1
              GROUP BY tu.tweet_id
           ) s
        ON s.tweet_id = t.tweet_id
    

    But we’ve made some assumptions about what should be done when is more than one row in tweets_url for a given tweet_id, or when there is no matching url, etc.

    If what you want is for a tweet to to marked as
    “spam=1” whenever that tweet is found to be related to ANY url that is marked as “spam=1”, and otherwise, the tweet should be marked as “spam=0″…

    This will set the spam column for every row in tweets, based on that rule…

    UPDATE tweets t
      LEFT
      JOIN ( SELECT tu.tweet_id, MAX(u.spam) AS spam
               FROM tweets_urls tu
               JOIN urls u ON u.url_id = tu.url_id
              WHERE u.spam = 1
              GROUP BY tu.tweet_id
           ) s
        ON s.tweet_id = t.tweet_id
       SET t.spam = IFNULL(s.spam,0)
    

    If you want to leave the spam column alone (leave it set to whatever it is set to) and ONLY want to update a row where the value is currently set to 0 and should be set to 1, according to the “matching url has spam=1”, you could do this:

    UPDATE tweets t
      JOIN ( SELECT tu.tweet_id
               FROM tweets_urls tu
               JOIN urls u ON u.url_id = tu.url_id
              WHERE u.spam = 1
              GROUP BY tu.tweet_id
           ) s
        ON s.tweet_id = t.tweet_id
       SET t.spam = 1
     WHERE t.spam = 0
    

    Note that predicate on the tweets table, we will ONLY be updating rows that have spam currently set to zero. And note that we don’t need to reference the value of the spam column from the urls table, we’re already testing that it’s equal to 1, so we can use a literal 1 in the assignment of the value to the tweets.spam column. Also note that we are doing an INNER JOIN (rather than a LEFT OUTER JOIN), so, again, we will only be updating rows that will be assigned a value of 1.


    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider following tables in MySQL database: entries: creator_id INT entry TEXT is_expired BOOL other:
Consider the following two MySQL tables: companies ----------------------- id ticker 1 AA 2 AAPL
Consider the following three tables: daterange stocks companies ----------- ---------------------------------- ---------------- _date stock_id nyse_date
Please consider the following three .NET types: I have an interface, an abstract class,
Consider the three following classes: EntityTransformer contains a map associating an Entity with a
Consider the following Ruby code analyzing a three-byte UTF-8 string: #encoding: utf-8 s =
Consider following text: $content=<<<EOT { translatorID: f4a5876a-3e53-40e2-9032-d99a30d7a6fc, label: ACL, creator: Nathan Schneider, target: ^https?://(www[.])?aclweb\\.org/anthology-new/[^#]+,
Consider the following three Hibernate entities: public class Car { @OneToMany(fetch = FetchType.LAZY) @Fetch(FetchMode.SUBSELECT)
Consider the following table : mysql> select * from test; +---------+ | col |
MySQL server version 5.0.45. Consider the following: ( SELECT CASE WHEN t.group_id = 12

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.