Hi. I've a table purchases which has the following fields:
I want to fetch that latest record which has fuel_type_id = 1.
Actually, this table gets entry when the fuel (petrol/ diesel) is purchased. So I want to fetch only that record of purchase which has fuel_type_id 1 or 2.
I've used this query but its not showing the latest record:
There are currently only 3 records, 2 records for fuel_type_id 1 and 1 for ID = 2;
The result this query brings me has the latest ID but not the latest Price?
Please guide me that what I'm missing?
Code:
purchase_id
vendor_id
fuel_type_id
purchase_quantity_liters
purchase_price_per_liter
date_of_purchase
is_deleted
Actually, this table gets entry when the fuel (petrol/ diesel) is purchased. So I want to fetch only that record of purchase which has fuel_type_id 1 or 2.
I've used this query but its not showing the latest record:
Code:
SELECT
MAX(p.purchase_id), Id
p.purchase_price_per_liter,
p.fuel_type_id
FROM
purchases p
WHERE
p.fuel_type_id = 1;
The result this query brings me has the latest ID but not the latest Price?
Please guide me that what I'm missing?