Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query minimum value of distinct records

Status
Not open for further replies.

learner45

Technical User
Jul 31, 2009
16
GB
Hi,

I have a view:
CustomerID OrderID ItemCost City
10 13 4500 A
30 17 3700 C
20 25 3457 B
50 19 7000 E
10 21 1900 A
40 32 2345 D
30 67 3457 C
20 89 4568 B

The field 'OrderID' is unique;

Is there a way to list the minimum 'ItemCost' by each 'CustomerId' - and the related 'OrderID' and 'City' ?

Thanks to all the helpful folks!

 
Code:
SELECT YourTable.*
FROM YourTable
INNER JOIN (SELECT CustomerId, 
                   MIN(ItemCost) AS ItemCost 
            FROM YourTable
            GROUP BY CustomerId) Tbl1
      ON YourTable.CustomerId = Tbl1.CustomerId
         YourTable.ItemCost   = Tbl1.ItemCost
NOT TESTED!

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
OK, what you want to get from the data you post?

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top