Tom, Restating the problem, you want the last two from the set ordered by invoice date. So, add
ORDER BY site_service.invoice_date DESC LIMIT 2; Probably just a typo, but I note your statement selects site_service.id and site.site_id but has site_service.site_id = site.id in the WHERE clause. Michael On Thu, 29 Nov 2001, Tom Beidler wrote: > I'm trying to write a query that will limit the results but not by the total > amount returned like a normal LIMIT. It's an invoice database and I would > like to return the last two invoices for a certain job. So if there are 100 > jobs with several invoice dates I would like to return a web page displaying > a table of invoice dates ordered by job name and LIMIT the invoice dates to > the last two invoice dates for each job. Here's my query so far; > > SELECT site_service.id, site_service.service_date, > site_service.invoice_date, site.site_id, site.name, site.state, site.status > FROM site_service, site WHERE site_service.site_id = site.id AND > site.company = 'Nextel' > > If I add LIMIT 2, I only get two invoices. I'm trying to get the last to > invoices for each site. > > Is this possible or is there another direction I should go? I checked out > the MySQL site without any luck. > > Thanks, > Tom > Michael Stassen University Information Technology Services Indiana University Bloomington [EMAIL PROTECTED] --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php