I need to use t-sql to query two tables. The first table is Books. The second table is Authors. For each Book record there could be multiple child Author records. I want to write a query that only returns the first Author record found for the current Book record. There are hundreds of thousands of records in the tables so I need the query to be efficient.
select a.FirstName, a.LastName, b.BookName
from Books b
left join
(
select TOP 1 t.BookID, t.FirstName, t.LastName
from Authors t
) a
on a.BookID = b.BookID
where b.BookClassification = 2
This query is not right. I only want to select the top 1 record in the Authors which match the BookID. How can I get the results I am looking for?