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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:15:23+00:00 2026-06-05T12:15:23+00:00

I’m afraid I’m no great shakes at SQL, so I’m not surprised I’m having

  • 0

I’m afraid I’m no great shakes at SQL, so I’m not surprised I’m having trouble with this, but if you could help me get it to work (doesn’t even have to be one query), I’d be grateful. trying to analyze some Twitter data using MySQLdb in Python, I’m running:

for u_id in list:
"
select e.user_id
from table_entities e
inner join table_tweets t on e.id = t.id
where e.type='mention' and t.user_id=%s
group by e.type having count('hashtag') < 3
"
%
(u_id)

(python syntax faked slightly to not show the unimportant stuff)

now, everything before the “group by” statement works fine. I’m able to extract user_ids mentioned in a given tweet (id is the PK for table_tweets, whereas there’s another row in table_entities for each mention, hashtag, or URL) matching the current position of my loop.

however — and I don’t think I’m formatting it anywhere near correctly — the group by statement doesn’t do a thing. what I mean to do is exclude all user_ids belonging to tweets (ids) that have 3 or more entries in table_entity with type=hashtag. I can sort of tell it’s not going to work as it is, since it doesn’t actually refer to the id column, but any way that I’ve tried to do that (e.g. by trying to make it part of the join clause) throws a syntax error.

advice is 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-05T12:15:24+00:00Added an answer on June 5, 2026 at 12:15 pm

    This doesn’t really do what you want.

    select e.user_id
    from table_entities e
    inner join table_tweets t on e.id = t.id
    where e.type='mention' and t.user_id=%s
    group by e.type having count('hashtag') < 3
    
    • The Select And group by clause aren’t doing what you expect. By putting e.user_id in the SELECT clause and not in the GROUP BY MySQL will select one arbitrary user_id for each e.type.
    • Having count('literalString') is the equivalent of Having COUNT(*) you can see this yourself by moving the Count(‘hashtag’) to the select clause.

    Here’s a Live DEMO of these points

    The result is that your query will only records if there are fewer than 3 mentions for the user.

    There are many way to accomplish what you’re trying I chose IN (you could also use Exists or an INNER JOIN to a subquery)

    SELECT e.user_id 
    FROM   table_entities e 
           INNER JOIN table_tweets t 
                   ON e.id = t.id 
    WHERE  e.type = 'mentions' 
           AND t.user_id =% s 
           AND e.user_ID  IN (SELECT e.user_id 
                                 FROM   table_entities e 
                                        INNER JOIN table_tweets t 
                                                ON e.id = t.id 
                                 WHERE  e.type = 'hashtag' 
                                        AND t.user_id =% s 
                                 GROUP  BY e.user_id 
                                 HAVING Count(*) >= 3) 
    

    the sub select finds all user ids that have less than 3 records in table_enties that have an e.type of “hashtag” and the user that matches % s

    The main select filter for ‘mentions’ and the user id again. This allows you you to select for one e.type and filtering on a count of another e.type.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build

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.