select project_id
from logger_projects
where exists (select 1
from logger_project_pkg_map
where package_id = :package_id
and project_id = logger_projects.project_id)
and not exists (select 1
from logger_project_pkg_map
where package_id <> :package_id
and project_id = logger_projects.project_id)
select project_id
from logger_project_pkg_map
where package_id = :package_id
select lv.variable_id,
lv.name,
lv.unit,
lv.type
from logger_variables lv
where (exists (select 1
from logger_project_var_map lpvm,
logger_project_pkg_map lppm
where lv.variable_id = lpvm.variable_id
and lpvm.project_id = lppm.project_id
and lppm.package_id = :package_id
)
or lv.package_id = :package_id
or lv.package_id is null)
$extra_where_clause