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

  • Home
  • SEARCH
  • 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 9175415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:54:34+00:00 2026-06-17T16:54:34+00:00

Assume these tables, with those fields: History: postID, viewerID Posts: postID, posterID Now this

  • 0

Assume these tables, with those fields:

History:

postID, viewerID

Posts:

postID, posterID

Now this query:

SELECT postID FROM history
WHERE postID IN (SELECT postID FROM Posts WHERE posterID IN (10,20,30)
AND viewerID=50

Will return all postIDS from posters 10,20 & 30, that viewer 50 has viewed.

What I’m after is a “group-by” that will be according to
the number of results of any posts per posterID.

For example, the results of the currently described query can have

100,200,300,300,300,100,400, 700, 500

Let’s say the first 7 results are from Poster 10 and the last 2 are from poster 20 –
So I need a result of:

posterID   viewsNum
10         7
20         2

My SQL level is intermediate, so it is not immediately clear for me how to achieve this,
sorry if there’s a ‘simple’ answer hiding inside 🙂

  • 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-17T16:54:35+00:00Added an answer on June 17, 2026 at 4:54 pm

    What you need here, is just a GROUP BY with an aggregate function COUNT(), and JOIN the two tables instead. Something like:

    SELECT 
      PosterID, 
      COUNT(postID) viewsNum
    FROM history h 
    INNER JOIN Posts p ON h.postID = p.PostID
    WHERE p.posterID IN (10,20,30)
      AND h.viewerID = 50
    GROUP BY posterID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

let's assume I have this numrequest table. it has these fields: id , id_user
For simplicity, assume all relevant fields are NOT NULL . You can do: SELECT
I have these four table assume that ring table consist of five fields(jewelry_id,ring_id,image,type,brand_id) Note
Let's assume I have 3 tables in a MySQL table with the following fields.
Hello again Stackoverflow people! Assume I have these words: smartphones, smartphone I want to
Consider these 2 pieces of code (you can assume execeptionObj is of type Object
I think Im tying myself up in knots with this and I assume there's
I have 2 tables : The table Data : id , plus many fields.
I have a complex table pulled from a multi-ActiveRecord object array. This listing is
I need to do a very complex query. At one point, this query must

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.