Classical SQL Interview Question

Exercise 1: SQL
Please read the instructions and proceed carefully as over 90% of applicants get this wrong.
Given the following tables and associated fields:
Person
PersonId, NameFirst, NameLast
Order
OrderId, PersonId, OrderDateTime
Write a SQL query that retrieves every person and their most recent order (if one exists).  Results should look something like this:
PersonId
NameFirst
NameLast
LastOrderId
LastOrderDateTime
1
James
Doe
1234
1/1/2013 9:01 AM
2
John
Doe
NULL
NULL
In the above results, the first is a person with at least one order, the second row is a person without an order.

Answer:


Comments