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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:44:43+00:00 2026-06-14T03:44:43+00:00

I have some kind of problem to understand something. I have the next table:

  • 0

I have some kind of problem to understand something.

I have the next table:

ID  PROD    PRICE
1   A        10
2   B        20
3   C        30
4   A        1
5   B        12
6   C        2
7   A        7
8   B        8
9   C        9
10  A        5
11  B        2

I want to get all the minimum prices of all the prod, meaning I want to get 3 records, the minimum price for every prod.
From the example above, this is what I want to get:

ID  PROD    MIN(PRICE)
4   A       1
11  B       2
6   C       2

This is the query I wrote:

select id, prod, min(price)
from A1
group by(prod);

But this is the records I got:

ID  PROD    MIN(PRICE)
1   A        1
2   B        2
3   C        2

As you can see the ID value is wrong, it is only give me some kind of line counter and not the actual ID value.

You can check it at the next link

What I’m doing wrong?

  • 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-14T03:44:45+00:00Added an answer on June 14, 2026 at 3:44 am
    SELECT  a.*
    FROM    A1 a
            INNER JOIN
            (
                SELECT Prod, MIN(Price) minPrice
                FROM A1
                GROUP BY Prod
            ) b ON a.Prod = b.Prod AND
                    a.Price = b.minPrice
    
    • SQLFiddle Demo

    For MSSQL

    SELECT ID, Prod, Price
    FROM
    (
      SELECT ID, Prod, Price,
            ROW_NUMBER() OVER(Partition BY Prod ORDER BY Price ASC) s
      FROM A1
    ) a
    WHERE s = 1
    
    • SQLFiddle Demo
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some kind of problem with jQuery selectors. Let's say i want to
Here's a problem. Developers have some kind of a task (develop certain feature), which
I want to have some kind of single list that is initialized in a
In my rails model I have some kind of template system. I want to
Horrible title, I know. I want to have some kind of wordwrap, but obviously
I have some kind of problem when adding models to my Ruby on Rails
I have some kind of controller: @Controller public class DefaultController { @RequestMapping(value=/index.html, method=RequestMethod.GET) public
I'm wondering if NFC chips have some kind of unique identifier? I have Mifare
I have a question about reflection I am trying to have some kind of
I've figured I have to do some kind of API where the Android app

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.