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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:42:36+00:00 2026-06-15T23:42:36+00:00

I have a data table similar to below: ID A B 10 5 blue

  • 0

I have a data table similar to below:

ID   A   B
10  5    blue
10  8    red
10  10  yellow
20  2    black
20  17  blue
30  7    red
30  12  green
30  50  black

Basically I want to write a mySQL query to output something like:

ID   A   B
10  5    blue
20  2    black
30  7    red

It gives only unique values of ‘ID’ and the minimum values of ‘A’ of each unique ‘ID’. ‘B’ is just the extra data that goes along with it in the row.

What should my query look like?

  • 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-15T23:42:37+00:00Added an answer on June 15, 2026 at 11:42 pm

    You can use a subquery to identify the min(a) value for each id and then join that back to your table:

    select *
    from yourtable t1
    inner join
    (
      select min(A) A, id
      from yourtable
      group by id
    ) t2
      on t1.id = t2.id
      and t1.A = t2.A
    

    See SQL Fiddle with Demo

    The result is:

    | ID | A |     B |
    ------------------
    | 10 | 5 |  blue |
    | 20 | 2 | black |
    | 30 | 7 |   red |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table similar to below: Data { id varchar(50), pId uniqueidentifier ,
I have a table with data similar to below: Group TimePoint Value 1 0
I have a data.table object similar to this one library(data.table) c <- data.table(CO =
I have the data table from the jquery plugin dataTables (http://datatables.net/) that I want
I have 1 table with similar data: CustomerID | ProjectID | DateListed | DateCompleted
I have a table with a Name field containing data similar to the following:
I have a data structure similar to the following picture. Table A has_many Table
I have a query as below to find duplicates in my table which contains
I have an excel sheet where in the data looks similar to the table
I currently have a table with all the data, using this data i want

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.