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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:31:39+00:00 2026-05-11T14:31:39+00:00

Hoping someone can help me out with this. Lets say I have a table

  • 0

Hoping someone can help me out with this.

Lets say I have a table called incoming_data with 4 columns:

primary_key_id serial_number counter selected_color 

I get data from a source that fills this table. The primary key has its identity turned on so it is not repeating. I will get duplicate serial numbers with different selected colors.

The counter is ever increasing coming from the device.

So what I want to do is select all the data I received today, group the data by serial number and only get the record with the highest counter value.

Simple:

SELECT      serial_number, MAX(counter) FROM        incoming_data  GROUP BY    serial number 

This works perfectly, except that I want to do something with the color information that I received.

If I add color to the select, then I get ALL the records since all the colors I received that day are different. That wont work.

If I could get the primary_key_id of the record then I could just query for the color but this doesn’t work either since each primary_key_id value is different I get them all.

Any suggestions on a better technique for doing this?

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. 2026-05-11T14:31:40+00:00Added an answer on May 11, 2026 at 2:31 pm

    Extract the relevant key, then join back to get ‘non key’. This works in MS SQL Server and later Sybase.

    SELECT      i.serial_number, i.counter, i.selected_color FROM    (    SELECT      serial_number, MAX(counter) AS maxc    FROM            incoming_data     GROUP BY    serial number    ) max    JOIN    incoming_data i ON max.serial_number = i.serial_number AND max.maxc = i.counter 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is bizarre, but I am hoping someone can help me out. I have
I am hoping someone can help me out with a quick question I have
I'm really hoping someone can help me out with this one. I've been stuck
hoping someone can help me out with this. I'm trying to figure out whether
I'm hoping someone can help out with this. I modified code from jQuery and
this is quite tricky for me and i'm hoping someone can help me out.
Alright, I am hoping someone can help me out. I apologize up front that
I am out of ideas here, so I'm hoping someone can help. Here is
im hoping someone can help me quickly with a question i have. As site
I am hoping someone can help me with a question i have relating to

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.