Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7784043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:01:25+00:00 2026-06-01T20:01:25+00:00

I have a table containing information on customers and products in an Access database:

  • 0

I have a table containing information on customers and products in an Access database:

custID product price
--------------------
1   objectA   12,5
1   objectB   54,51
1   objectC   14,85
2   objectE  188,84
2   objectC   14,85
2   objectD  188,84

From that table I would like to get the most expensive product a customer bought by SQL. I tried this:

SELECT a.custID, a.product, max(a.price)
FROM orders AS a INNER JOIN orders AS b ON (a.custID=b.custID) AND (a.price<=b.price)
GROUP BY a.product, a.custID
HAVING count(*)<2;

The result is

1   objectB  54,51

It works all right for all cases where the maximum price occurs only once, but fails when two products have the same (maximum) price. How to make sure to get a result for each customer? (I don’t care wether it will by objectD or objectE for customer 2).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:01:27+00:00Added an answer on June 1, 2026 at 8:01 pm
    SELECT a.custID, MAX(a.product), MAX(a.price)
    FROM orders AS a 
    WHERE a.price = (select MAX(b.price) from orders b where a.custID=b.custID)
    GROUP by a.custID
    

    Just a side note:
    If you have a more advanced SQL server that supports windowing functions, like SQL Server 2008 you can instead write

    SELECT custID, product, price FROM (
        SELECT custID, product, price,  ROW_NUMBER()
            OVER (partition by custid order by price desc) AS rowNo
        FROM orders 
    ) AS a
    WHERE a.rowNo = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Database table containing product information as follows: ProductID, KeywordID, ProductDescription and
I have a (DB2) database table containing location information, one column of which is
Say I have at database table containing information about a news article in each
I have a database table containing network information (servers, clusters etc). Is there any
I have a MySQL database table containing information about places. I'm trying to fetch
I have an ACCESS table named Reviewer Score Averages containing information on company reviews
I have table containing information about a series of x number of quizzes. It
I have a table containing transaction information on items. The possible transactions are purchase
I have a Table containing some information that I need. All these rows also
I have a table containing persons information (one row per person) and another table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.