use bugs;

select (
	select login_name from profiles where userId = (
		select userid from maintainer where product_id = bugs.product_id
		union
		select userid from maintainer where product_id = (
			select id from products where name = (
				select name from product_groups where id = bugs.product_id
			) 
		) 
	limit 1 
	) 
) as manager from bugs where (bugs.bug_id=45199);
