This is a question I got at an interview. They asked me to describe the differences in the following 3 scenarios.
Query #1:
SELECT p.name, c.email
FROM PersonalDetails as p
JOIN ContactDetails c
ON p.id = c.id
WHERE p.region = 'UK'
Query #2
SELECT p.name, c.email
FROM PersonalDetails as p
LEFT JOIN ContactDetails c
ON p.id = c.id
WHERE p.region = 'UK'
Query #3:
SELECT p.name, c.email
FROM PersonalDetails as p
LEFT JOIN ContactDetails c
ON p.id = c.id AND p.region = 'USA'
My answer- 1st is an inner join and 2nd is a LEFT JOIN.Therefore 1st query will return only matching records from both tables and 2nd query will return matching records from both tables and all records from left table.
Their answer - the first 2 queries will return the same result. The 3rd query will be executed as an inner join
Can anyone explain how this can happen...???
Thanks in advance