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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:24:02+00:00 2026-06-18T08:24:02+00:00

Okay my question is similar to Counting and grouping same named column in different

  • 0

Okay my question is similar to Counting and grouping same named column in different tables (mysql) but since it might help people looking for exact solution on the internet (like me) I am separating the two questions.

So my table looks similar to that in the link above, with some new columns
Table 1:

id age gender published
1   10  M       1
2   11  F       1
3   11  F       0

Table 2:

id table1id age gender
1    2       11   F
2    2       12   M
3    3       12   M

I want to count and group rows from both tables where published = 1. For the second table it should check the published value from the row given by table1id in Table 1. Table1id is the id of the row in Table 1 denoting that table 2 is a subset of table 1. So the result should look something like the following:

age count
10  1
11  2
12  1

Notice that third row from table 1 is not counted because published is 0. And third row from table 2 is not counted because table1id = 3, which means it’s a subset of the 3rd row of table 1 (which has published = 0)

Thanks for your help 🙂

  • 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-18T08:24:03+00:00Added an answer on June 18, 2026 at 8:24 am

    Try this:

    SELECT age, COUNT(age) cnt
    FROM
    (
        SELECT
            T2.age 
        FROM Table1 T1
            JOIN Table2 T2
                ON T1.Id = T2.table1id
        WHERE T1.published = 1
        UNION ALL
        SELECT age
        FROM Table1
        WHERE published = 1
    ) A
    GROUP BY age
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay this is definitley an easy question and a stupid one but since I
Okay so I know I asked a similar question a while ago, but this
Okay, I've asked a similar question before, but I've spent about eight hours (really)
I have searched the forum for this , but found no similar question, okay
Okay, so there's another similar question that I found to this on SO but
Okay, I kinda asked this question already, but noticed that i might have not
Okay, so this might be kind of strange but here's the question: I have
Okay this is similar to my last question but what I ended up doing
Okay this is definitely a n00b question but here goes. The way I understand
okay so this is probably a soft pitch question for sombody, but I want

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.