Quantcast
Channel: VBForums - Database Development
Viewing all articles
Browse latest Browse all 2918

How to fetch maximum record from my table in mySql database

$
0
0
Hi. I've a table purchases which has the following fields:

Code:

purchase_id
vendor_id
fuel_type_id
purchase_quantity_liters
purchase_price_per_liter
date_of_purchase
is_deleted

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:

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;

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?

Viewing all articles
Browse latest Browse all 2918

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>