Skip to content

Instantly share code, notes, and snippets.

@ishideo
Last active November 22, 2018 15:07
Show Gist options
  • Save ishideo/30c2ad999bfa0e37d7c7afcd400e3a5c to your computer and use it in GitHub Desktop.
Save ishideo/30c2ad999bfa0e37d7c7afcd400e3a5c to your computer and use it in GitHub Desktop.
select distinct
u.id
, u.last_name
, u.first_name
, u.last_name_kana
, case when d.user_id is null
then 2
when d.user_id is not null
then 1
end
from employees as e
left join users u
on e.user_id = u.id
left outer join deliverers as d
on e.user_id = d.user_id
and e.employee_id = d.employee_id
where e.employee_id = 10000001
order by
u.last_name_kana asc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment