Query to get username from child table with specific condition

Here is one method that should work in any database:

select t1.*, t2.region
from table1 t1 join
     (select t2.username, max(region) as region
      from table2 t2
      group by t2.username
      having count(*) = 1
     ) t2
     on t1.username = t2.username;

Browse More Popular Posts

Leave a Comment