Forums Register Login

JPQL Question with Left Join

+Pie Number of slices to send: Send
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?


+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Oh! Thanks Raf.
+Pie Number of slices to send: Send
So as per this link can we say that the Department is the LEFT entity (table) and Employees is the RIGHT entity (table).
No more fooling around. Read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1356 times.
Similar Threads
Test 484 ... LONG POST
question about EJB QL
which join to use?
Cannot understand MySqlQuery Working.
Question based on hashcode()
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 08:11:27.