```
client_id pet_id   clinic_id invoice_date total service unqid
20.20003  20.26777 20        1/24/2015    100        1     1
20.20001  20.26355 20        1/11/2015     50        2     2
20.20001  20.26355 20        1/12/2015    200              4
20.20001  20.26355 20        1/13/2015    600              5
20.20003  20.26777 20        1/15/2015    350              6

```

From the table above, I am trying to make a sql query that gives me the 'total' of the first(lowest) 'invoice\_date' grouped by 'pet\_id'.

Using this, I can get an average for the first invoice. Problem is I cant get this to work.

I have tried:

```
mysql_query("SELECT total FROM invoice WHERE clinic_id='$clinic_id' GROUP BY pet_id ORDER BY invoice_date ASC");  

```

But this gives me 50, 100
It should be 50 and 350 (Unqid 2 and 6).

How would I accomplish this? Also, why does my query not work? I thought it would give me the total grouped by pet\_id (making sure I only get 1 invoice per pet) and ordered by the lowest invoice\_date (making sure its the first one).