mysql - Determine type of sub tables -


problem: have modelled mysql tables emulate inheritance between tables, example:

example model

is there way query employees , output type of employee are?

the desired output be:

id   name                             salary     type ------------------------------------------------------------ 1    john doe                         2000       executive 2    jane doe                         1000       manager 3    nick carter                      500        intern 

any appreciated!

you have 1 table maintaining type of employe in case can as

select  e.* , case    when i.employee_id not null 'intern'   when m.employee_id not null 'manager'   when ex.employee_id not null 'executive' end `type`  employee e  left join intern on i.employee_id = e.id left join manager m on m.employee_id = e.id left join executive ex on ex.employee_id = e.id 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -