Skip to content
Advertisement

How to count result values from join query in another table?

I have two tables like so:

I want result table where it displays all the users with their names and sex from table 2 who changed their sex at some point along with a count of how many users each name has. So this would be the result table:

Currently im using this query:

However the count column just counts from the resulting join table and not from original table1. Any ideas? thanks.

Advertisement

Answer

If I follow this correctly, one option use a lateral join and filtering:

Basically this filters table1 on users that have different sex or whose sex is different than in table2.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement