Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

itinigam's avatar

Group by and order by in the same query

I need to fetch the results from a table using group by and order by in the same query. Basically I need to fetch the latest transaction from the transactions table based on two columns i.e. latest row based on unique combination of two columns.

I need to fetch the latest row grouped by two columns.

Eg: I have a table transactions which contains the transactions of the quotations of a request Columns are:

  1. Quote Id
  2. Payment Type (Advance Payment, Full Payment, Vendor Payment)

I need to get the latest transaction on the basis of Quote Id and Payment Type as there may be several transactions of a quotation but the latest one is success. So, I need to fetch the latest transaction which was success for the quote and payment type - Vendor Payment.

0 likes
0 replies

Please or to participate in this conversation.