DELIMITER \\
DROP PROCEDURE IF EXISTS users_get_by_application_key\\
CREATE PROCEDURE `users_get_by_application_key`(in i_api_key char(32))
BEGIN
	select 
		u.*,
		if(r.default_user_id = u.id, 'yes', 'no') is_default
	from 
		users_client_registry_jct jct
			join users u on u.id = jct.users_id
			join client_registry r on r.id = jct.client_registry_id
	where
		r.application_key = i_api_key;
END\\
DELIMITER ;