Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 544
  • Last Modified:

Highest number from multiple numbers in a column

If you have multiple rows for and item, how can you select the highest number in a column.

Example:

Item    Supplier    cost
100     shopper     3.50
100     Freds        3.60
100      Sams       3.55


Answer I need would be 3.60
0
DGinnett
Asked:
DGinnett
  • 6
  • 5
  • 2
  • +1
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
select item, max(cost) from yourtable
group by item
0
 
riaancorneliusCommented:
What database is it? MySQL, MSSQL, Access... ?

for MSSQL:
select TOP 1 cost from table1 ORDER BY cost
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
small correction to riaancornelius, as the default order by is ASC:


select TOP 1 cost from table1 ORDER BY cost DESC

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
riaancorneliusCommented:
of course. Thanks angel :)
0
 
AristoCommented:
SELECT MAX(cost)
FROM TableName

This will give you one result for all the table:
3.60

If you need a list of the highest price for each product then:
SELECT item,MAX(cost)
FROM TableName
GROUP BY item

This will give you one result for each item:
item                cost
-----               ------
100                 3.60
101                 10.1
  .                     .
  .                     .
  .                     .
0
 
DGinnettAuthor Commented:
DB is Access
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
did you already try the suggestions with MAX() and GROUP BY ?
should work fine in access...
0
 
DGinnettAuthor Commented:
I'm using this in query and in the expression builder I have

item_LC: Format(
(select  [Item]![Item_style] , max( [Supplier_data]![LC_cost])
from [Supplier_data]
group by [Supplier_data]![LC_cost])
,"#.00")

When I run the query I get

you have written a subquery that can return more than one field without using the exist reserved word in the main query's from clause.  revise the select statement of the subquery to request only one field.

Also, how can you store this info in a table fieldname
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
first, you used GROUP BY LC_Cost field, but actually seems you want to max of that. that is not correct.

now, you did not answer the question:
do you want to overall global max value, or per item_style?

global overall max value (highest cost):
item_LC: Format( DMax( "LC_Cost", "Supplier_data", "") ,"#.00")

per current style (column item_style assumed in the existing query:
item_LC: Format( DMax( "LC_Cost", "Supplier_data", "Item_Style='"& Item_Style & "' " ) ,"#.00")
0
 
DGinnettAuthor Commented:
Addition to above,  Added supplier_data table and linked style_no.

ran again and getting....

Now getting SQL statement could not be executed because it contins ambiguous outer joins.  To force one of the joins to be performed first, create a separate query that performs the first join and then inlude the query in your SQL statement.
0
 
DGinnettAuthor Commented:
angelIII per your response 10/29/2006 08:03AM PST

max value per item_style.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
per current style (column item_style assumed in the existing query:
item_LC: Format( DMax( "LC_Cost", "Supplier_data", "Item_Style='"& Item_Style & "' " ) ,"#.00")
0
 
DGinnettAuthor Commented:
angelIII

I did get it to work in the following statement

item_LC: Format(DMax("LC_Cost","Supplier_data","[Style_no]='" & [Item]![Item_Style] & "' "),"#.00")
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
glad I could help
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 6
  • 5
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now