I am new to SQL. And I am practicing SQL questions on leetcode.
This is the question: https://leetcode.com/problems/combine-two-tables/
Why can't I use:
select Person.FirstName, Person.LastName, Address.City, Address.State
from Person,Address
where Address.PersonId=Person.PersonId
It failed in this case:
Input:
{"headers": {"Person": ["PersonId", "LastName", "FirstName"], "Address": ["AddressId", "PersonId", "City", "State"]}, "rows": {"Person": [[1, "Wang", "Allen"]], "Address": []}}
Output:
{"headers": ["FirstName", "LastName", "City", "State"], "values": []}
Expected:
{"headers": ["FirstName", "LastName", "City", "State"], "values": [["Allen", "Wang", null, null]]}
The accepted answer is:
select Person.Firstname, Person.lastname, Address.city, Address.state
from Person
left join Address on Person.PersonId = Address.PersonId
Why is this? I thought both of the queries would accomplish the same thing and have the same effect.