I have a table that contains the ids of receipts, each associated with a the id of a client. I have been trying for a while now, to get the biggest id and the second biggest id of the receits associated with each client.
I have tried the following:
select max(id), client
from table
where deleted = 0
group by cliente
order by id;
but to no avail. My idea was to get the second biggest by taking first the biggest and then excluding the id of the biggest from a query that would take all of the receipts, but i cant even get the query that takes the biggest receipts to work.
Any suggestions?