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 775825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:21:13+00:00 2026-05-14T19:21:13+00:00

I can tell it best by explaining the query I have, and what I

  • 0

I can tell it best by explaining the query I have, and what I need.

I need to be able to get a group of items from the database, grouped by category, manufacturer, and year made. The groupings need to be sorted based on total amount of items within the group. This part is done with the query below.

Secondly, I need to be able to show an image of the most expensive item out of the group, which is why I use MAX(items.current_price). I thought MAX() gets the ENTIRE row corresponding to the largest column value. I was wrong, as MAX only gets the numeric value of the largest price. So the query doesnt work well for that.

SELECT
    items.id,
    items.year, 
    items.manufacturer,
    COUNT(items.id) AS total,
    MAX(items.current_price) AS price,
    items.gallery_url,
FROM 
    ebay AS items
WHERE
    items.primary_category_id = 213
AND
    items.year <> ''
AND
    items.manufacturer <> ''
AND
    items.bad_item <> 1
GROUP BY  
    items.primary_category_id,
    items.manufacturer,
    items.year
ORDER BY  
    total DESC,
    price ASC
LIMIT 
    10

if that doesnt explain it well, the results should be something like this

id 10548

year 1989

manufacturer bowman

total 451

price 8500.00 (The price of the most expensive item in the table/ not the price of item 10548)

gallery_url http://ebay.xxxxx (The image of item 10548)

A little help please. Thanks

  • 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-05-14T19:21:14+00:00Added an answer on May 14, 2026 at 7:21 pm

    I’ve had this same problem, and I’m fairly certain you have to do two queries (or a subquery, that’s a matter of taste).

    The first query is like what you have (except id isn’t helping you).
    The second query uses the GROUP BY fields and one (one!) MAX field to get the id and any other meta-data you need.

    I believe this is the implementation, although it’s hard to test:

    SELECT
        items.id,
        items.year, 
        items.manufacturer,
        items.gallery_url
    FROM
        ebay as items
    NATURAL JOIN
        (
            SELECT
                COUNT(items.id) AS total,
                MAX(items.current_price) AS current_price,
                items.primary_category_id,
                items.manufacturer,
                items.year
            FROM 
                ebay AS items
            WHERE
                items.primary_category_id = 213
            AND
                items.year <> ''
            AND
                items.manufacturer <> ''
            AND
                items.bad_item <> 1
            GROUP BY  
                items.primary_category_id,
                items.manufacturer,
                items.year
            ORDER BY  
                total DESC,
                price ASC
            LIMIT 
                10
        ) as bigones
    ORDER BY  
        bigones.total DESC,
        bigones.current_price ASC
    

    This documentation may help you understand what’s going on:

    http://dev.mysql.com/doc/refman/5.1/en/group-by-hidden-columns.html

    … all rows in each group should have the same values for the columns that are ommitted from the GROUP BY part. The server is free to return any value from the group, so the results are indeterminate unless all values are the same.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone tell me the best way to do three seperate get requests from
can anyone tell me what is the best way to do something like, from
so from what i can tell, you have to specify artifacts and working directory
ok can someone tell me the best tree view control in jquery? apart from
Can anyone tell me the best way to call FoxPro 9 code from a
As best I can tell cucumber is only hitting the database once between these
Can anyone tell me the best way to send some xml data from one
I tried to follow this example from Microsoft, best I can tell I did
Best I can tell from here , I am not breaking any rules with
As you can probably tell by the title, I'm not sure the best way

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.