SELECT c1.address
FROM users c1, users c2
WHERE c1.address = c2.address
AND c2.first_name = 'John'
I don’t understand what the third line is doing. I don’t understand it because this query returns two separate addresses even though in the condition it says address 1 must match address 2?
What am I missing?
Edit:
The table has three records of users. two of those users share the same first name ‘john’
Edit:
Also, why do we need to do this, instead of the following?
SELECT address
FROM users
WHERE first_name = 'John'
Considering you’re only selecting the
address, those selects are equivalent. It returns two addresses because there are two “Johns”.Joining on address would allow you to figure you who else lives with John. For example:
would tell you the names of everybody who lives with a “John”.