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 7719911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:31:58+00:00 2026-06-01T03:31:58+00:00

I have the following tweets table: tweet_id user_id text ————————————————— 1 2 this is

  • 0

I have the following “tweets” table:

tweet_id  user_id  text
---------------------------------------------------
1         2        this is a tweet with (TAG} in it
2         2        tweet without a TAG
3         2        {TAG} another {TAG} tweet
4         4        look at my {TAG} and weep!

I want to count, for each user, the number of tweets that contains {TAG} at least once. The tag could be anywhere in the tweet: at the beginning, in the middle or at the end (read: not followed by a space or anything). The table has millions of records, so I’m looking for an efficient way to do this. My first attempt was

SELECT COUNT(tweet_id) FROM tweets WHERE `text` LIKE '%{TAG}%' AND user_id = 2

but this returns 0 while, in this example, it was expected to return 2. So two questions: (i) what am I doing wrong and (ii) is there a more efficient way to do this?

[EDIT]

I would like to insert the result into the “users” table:

user_id  tweets_with_tag
2        2
3        0
4        9

Is it possible to count and insert in the same query?

  • 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-01T03:31:59+00:00Added an answer on June 1, 2026 at 3:31 am

    To Insert:

    INSERT INTO users(user_id, tweets_with_tag) 
    SELECT COUNT(tweet_id) as 'tweets_with_tag',
    [user_id] as 'user_id'
    FROM tweets 
    WHERE text LIKE '%{TAG}%'
    GROUP BY user_id
    

    Edit: If the User table already exists do the following

    UPDATE users
    SET tweets_with_tag = (
        SELECT COUNT(tweet_id) as 'tweets_with_tag'
        FROM tweets 
        WHERE text LIKE '%{TAG}%' and user_id = users.user_id
        GROUP BY user_id)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following table: Tweet(id: integer, from_user: string, tweet_text: string, tweet_id: integer, course_id:
I have the following line of code: <a href=javascript:; onClick=tweeet('myid')>My Tweets!</a> Now while this
I have several tables, containing (a.o.) the following fields: tweets: -------------------------- tweet_id ticker created_at
Consider the following tweets: RT @username This is my tweet Check this! RT @username
I have big collection of tweets stored in MongoDB. Tweets look like this one:
Consider the following tables users tweets --------------------------------- --------------------------- user_id num_retweets sum_retweets tweet_id user_id retweeted
Consider the following table tweets --------------------------------- tweet_id nyse_date class type --------------------------------- 1 2011-03-12 2
Consider the following table: tweets ----------------------- id tweet class ----------------------- 1 Foo bar baz!
Consider the following three MySQL tables: tweets urls tweets_urls --------------------------- --------------------- ---------------- tweet_id text
All, I have the following code to retrieve some Tweets: if( ! $tweet )

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.