Mathias wrote:

Selon Russell Horn <[EMAIL PROTECTED]>:

This must have come up before, but I've not found it using a google
search.

I have two tables customer and purchases

customer:
 customerID
 customerName

purchases:
 purchaseID
 customerID
 purchaseDate
 purchaseValue

Is it possible in MySQL to join the tables so I only get the value of
the latest purchase? Or is this something that's better done in PHP, say
select all my customers and then one at a time do a query to select the
value of their last purchase?

Thanks!

Russell.

Hi ,
join the tables with max(purchase_date) in the select,and of course group by
customer_id


Hope that helps
:o)
Mathias

Join with MAX(purchase_date)? Do you mean in a subquery? If so, that requires 4.1.

This is a FAQ. Three solutions are given in the manual, a subquery solution for 4.1+, a temporary table solution for all versions, and a trick.
<http://dev.mysql.com/doc/mysql/en/example-maximum-column-group-row.html>

Michael


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to