mysql - How avoid joining multiple times to the same table to get results back in single rows? -


i have schema requires joining same table multiple times more information on data pointed columns. below example schema shows situation:

sql fiddle: http://sqlfiddle.com/#!9/7a4019/1

create table state ( employee int not null, boss int, manager int, rep int );  create table employee ( id int not null, name varchar(255) not null );  insert employee (id, name) values (1, "joe"); insert employee (id, name) values (2, "john"); insert employee (id, name) values (3, "jack"); insert employee (id, name) values (4, "jeff"); insert employee (id, name) values (5, "jason");  insert state (employee, boss, manager, rep) values (1, 2, 3, 4); insert state (employee, boss, manager, rep) values (2, 3, 3, 4); insert state (employee, boss, manager, rep) values (3, null, null, 4); insert state (employee, boss, manager, rep) values (4, 3, 3, null); insert state (employee, boss, manager, rep) values (5, 2, 3, 4); 

currently, way know information in single rows each employee, left joining multiple times this:

select employee, b.name boss, m.name manager, r.name rep state left join employee b on b.employee = state.boss left join employee m on m.employee = state.manager left join employee r on r.employee = state.rep 

is there way without joins , without subqueries?

you asked:

is there way without joins , without subqueries?

not really. using join operations precisely they're intended used -- each join reflects specific relationship between rows of table.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -