java - HQL language how to join query two tables like in code -
i have 3 tables:
manager
companymanager
company
one many
i need managers without company, in java code can explain:
list<long> managerswithcompany = (list<long>) session.createquery("select distinct mc.idmanager managerscompany mc").list(); list<long> allmanagers = (list<long>) session.createquery("select m.id manager m").
//for example in managerswithcompany have ids: 2 3 4
//for example in allmanagers have ids: 1 2 3 4 5
so, how create query, give me 1 5?
again, need managers have not company
code on java, need query without code, know?
arraylist<long> answer = new arraylist<>(); allmanagers.foreach(actman -> { boolean add = true; (long allmanager : managerswithcompany ) { if (actman.equals(allmanager)) { add = false; break; } } if (add) answer.add(actman); });
using sql:
select m.id manager m not exists (select * managerscompany mc m.id = mc.idmanager)
Comments
Post a Comment