I have a table with waybill_items orders, in which waybill is the order number and name is the name. On one order can go several items.

How can I make a selection by the last order (he, it turns out, the maximum waybill value) of all items?

If I use the normal MAX function, then it gives only one line from the name, and I have about 20 of them.

 SELECT MAX(waybill), name FROM waybill_items 

    1 answer 1

    It is possible to calculate max in the subquery. the waybill value, then use it in WHERE to select rows with this waybill value:

     SELECT * FROM waybill_items WHERE waybill = (SELECT MAX(waybill) FROM waybill_items) 
    • Thanks, it happened - Sergey