select user, date_borrow, book, comments
from booksborrow ZZ
where date_borrow =
( select max(date_borrow)
from booksborrow
where user = ZZ.user )
this is a correlated subquery
each row in the outer table, the table with the alias ZZ (the correlation variable), is compared to all the other rows in its group
this group consists of those rows which have the same user
if you think about it procedurally -- start with the first row in the table, get all the rows that have the same user, sort them by date, take the top 1, get the next row in the table, get all the rows that have the same user, sort them by date, take the top 1, and so on -- then your brain will turn to tapioca
instead, think of what you want
the last date for each user
the users must be grouped
correlation is one way to do that
(GROUP BY is another, but in this example the correlated subquery is a lot neater)
so don't think about it procedurally, think about how to describe the results you want, and let the database figure out how to do it
rudy
http://r937.com/