One-to-one SQL join from among the many?
I have two tables in MySQL. One of them (let’s say, for the purpose of simplicity) is a listing of books. The other is a listing of reviews of those books along with a 1-5 ranking. Each book may have 0 or more reviews. It’s your standard one-to-many relationship.
However, I want to have a one-to-one left join in order to generate a listing of books along with their most recent ranking, like such:
Da Vinci Code: 1
The Omnivore’s Dilemma: 5
The Half-Blood Prince: N/A
Freakonomics: 3
Cesar’s Way: 3
Again, this is not the average ranking, simply the one accompanying the most recent review, assuming there is one.
Here’s the question: What’s the simplest method of joining the two tables to include only the ranking from that most recent review? I just know I’m overlooking something simple.
13 Comments