0

So my problem is that I have a table in which I want to print the Minimum price of a book but in the table have 2 books which has the Lowest price so when ever I execute it the output only show me the price for 1 book and the details of the 1 book I want it to show me the 2 books which has the same Lowest price for that I write a query but it's not working can someone help me

Select *,Min(price) From Books

1 Answers1

0

Min returns the minimum column value. In case you have n identical minimum values you need to do some post processing.

SELECT price FROM TABLE Books WHERE price IS NOT NULL ORDER BY price DESC;

This will return you the minimum price value in the first row of the resulting DataTable.

Next loop through your result set and check if there are "multiple minimum values".

for(int i = 1; i < datatable.Rows.Count; i++)
if( datatable.Rows[i][0] > datatable.Rows[i-1][0] )
{
  this is the first "no match", results with index i = 0 to i - 1 
  have the samevalue
}
kmcontact
  • 21
  • 3