简体   繁体   中英

JPA where in sub query

  public class Emp {
      Integer eid;
      String ename;
      long sal;
      Dept dept;    
    }

    public class Dept {
      Integer deptid;
      String deptname;
    }

     (List<Emp>) em.createQuery("select e from Emp e where e.sal=(select em.sal from Emp where em.eid=:a "))
                     .setParameter("a",empid)
                     .getResultList();

I want get all matched Emp list by passing emp id. Is it possible in Jpa. Please help me.

Yes, It is possible. And you may try this;

  select e1 from Emp e1,Emp e2 where e1.sal = e2.sal and e2.eid =: a;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM