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

The Archive Base Latest Questions

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

i have a problem concerning a select query in MYSQL i have two different

  • 0

i have a problem concerning a select query in MYSQL

i have two different tables and i want to obtain a certain result

i used COUNT method which gave me only the results (>=1)

But in reality , i want to use all counts with zero included how to do it?

My query is:

SELECT 
    first.subscriber_id, 
    second.tag_id,
    COUNT(*)
FROM 
    content_hits first  
    JOIN content_tag second ON first.content_id=second.content_id 
GROUP BY  
    second.Tag_id,first.Subscriber_id<br>

First table:Content_hits

CONTENT_ID  SUBSCRIBER_ID   
30          1   
10          10  
34          4   
32          2   
40          3 
28          3   
30          6   
31          8   
12          3 

Second table:Content_tag

CONTENT_ID   TAG_ID
1            1
2            1
3            1
4            1
5            1
6            1
7            1
8            1
9            1
10           1
11           2
12           2
13           2
14           2

Result but incomplete For example:Subsrciber6 for tag_id=1 should have a count(*)=0

subscriber_id   tag_id   COUNT(*)
1               1        4
2               1        7
3               1        2
4               1        1
5               1        3
7               1        2
8               1        1
9               1        1
10              1        3
1               2        2
2               2        3
3               2        2
  • 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:30:41+00:00Added an answer on June 1, 2026 at 3:30 am

    Now that you have further elaborated on what you actually want to achieve, it can be seen that the problem is much more complex. You actually want all combinations of subscriber_id and tag_id, and then count the number of actual entries in the joined table product. whew. So here goes the SQL:

    SELECT combinations.tag_id,
           combinations.subscriber_id,
    
    -- correlated subquery to count the actual hits by tag/subscriber when joining
    -- the two tables using content_id
    
           (SELECT count(*)
            FROM content_hits AS h
            JOIN content_tag AS t ON h.content_id = t.content_id
            WHERE h.subscriber_id = combinations.subscriber_id
            AND t.tag_id = combinations.tag_id) as cnt
    
    -- Create all combinations of tag/subscribers first, before counting anything
    -- This will be necessary to have "zero-counts" for any combination of
    -- tag/subscriber
    
    FROM (
      SELECT DISTINCT tag_id, subscriber_id
      FROM content_tag
      CROSS JOIN content_hits
    ) AS combinations
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using LaTeX and I have a problem concerning string manipulation. I want
I have a more or less good working query (concerning to the result) but
I have some problem converting a MYSQL query to CI syntax. This my MySQL
I have a weird problem concerning mysql timezone. In my website config file i
I have problem concerning python packages and testing. I'm writing an application using wx
I have quite a problem concerning the use of relational database concepts in Delphi
I have problem with return statment >.< I want to store all magazine names
This is my SQL query. I have data in my tables for this query.
I ran into a problem with Hibernate concerning hql query execution on classes which
I have come across a weird problem concerning composite keys and one-to-many relationship. I

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.