TOP 5 Query not working

M

Michael Kintner

I have a query that for some reason will not show only the top 5 records.

Where this comes from is a report and within that report I have another
report and only wish to show the top 5 records. But the results are very
crazy and sometimes I get nothing.

Any ideas on how to fix this?

Thank you in advance,
Mike
 
J

John Vinson

I have a query that for some reason will not show only the top 5 records.

Where this comes from is a report and within that report I have another
report and only wish to show the top 5 records. But the results are very
crazy and sometimes I get nothing.

Any ideas on how to fix this?

Thank you in advance,
Mike

"Doctor, I don't feel good. What should I take?" <g>

Please post the SQL view of the query, perhaps with an example of the
data and the results you're getting. It's impossible to determine what
you're doing wrong if you don't tell us what you're doing.

John W. Vinson[MVP]
 
M

Mike

SELECT TOP 5 ProductCodes.ProductCode, TankInfo.TankNumber,
ProductCodes.ProductShortDescr, ProductCodes.ProductLongDescr,
ProductCodes.SpecificGravity, TankInfo.TankID, TankInventory.MeasuredDate,
TankInventory.MeasuredHeightFT, TankInventory.MeasuredHeightIN,
TankInventory.Temperature, TankInventory.Dept, TankInventory.Gravity
FROM TankInfo INNER JOIN (ProductCodes INNER JOIN TankInventory ON
ProductCodes.ProductCodeID = TankInventory.ProductCodeID) ON TankInfo.TankID
= TankInventory.TankID
ORDER BY TankInventory.MeasuredDate DESC;

I try this but only shows 1 record when it should show 5 records. Please
help.

Thanks.
 
J

John Vinson

SELECT TOP 5 ProductCodes.ProductCode, TankInfo.TankNumber,
ProductCodes.ProductShortDescr, ProductCodes.ProductLongDescr,
ProductCodes.SpecificGravity, TankInfo.TankID, TankInventory.MeasuredDate,
TankInventory.MeasuredHeightFT, TankInventory.MeasuredHeightIN,
TankInventory.Temperature, TankInventory.Dept, TankInventory.Gravity
FROM TankInfo INNER JOIN (ProductCodes INNER JOIN TankInventory ON
ProductCodes.ProductCodeID = TankInventory.ProductCodeID) ON TankInfo.TankID
= TankInventory.TankID
ORDER BY TankInventory.MeasuredDate DESC;

I try this but only shows 1 record when it should show 5 records. Please
help.

If you open the Tables, are there in fact five records in
TankInventory? How many records are there in TankInfo, TankInventory?
Does each TankInventory record have a non-NULL ProductCodeID matching
a record in ProductCodes? If you remove the TOP 5 predicate do you see
just one record, or more than 5?

John W. Vinson[MVP]
 
Top