user1734248
user1734248

Reputation: 37

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.

Upvotes: 0

Views: 180

Answers (1)

mstzn
mstzn

Reputation: 2931

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;

Upvotes: 3

Related Questions