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 🙂
Try this: