Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

JPQL Question with Left Join

 
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question Number 43 of the Diagnostic Exam of WhizLabs preparation kit.

SELECT d
FROM Dept d LEFT JOIN FETCH d.employees
WHERE d.department_no = 1


[A] From the above query only employees of department no 1 will be retrieved.
[B] From the above query those departments will be retrieved which has employee and have department_no not equals to 1.
[C] This will retrieve all the departments, which has department_no equals to 1. It will also retrieve the associated employees with the set of departments.
[D] This is an invalid query.



According to the WhizLabs, the correct answer is C.
Can someone tell me why the answer B is wrong?


 
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all because option B says that the departments retrieved will not have id = 1, but the where clause asks for 1. Second, it retrieves the department either if it has any employee, or if it has no employees - it is a left outer join.
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh! Thanks Raf.
 
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So as per this link can we say that the Department is the LEFT entity (table) and Employees is the RIGHT entity (table).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!