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

The Archive Base Latest Questions

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

Assuming the following table: USER COLOR ORDER ================== JOE RED 1 JOE BLUE 2

  • 0

Assuming the following table:

USER  COLOR  ORDER
==================
JOE   RED    1
JOE   BLUE   2 
PHIL  BLUE   3

Joe first chose red, then chose blue as his favorite color… How do you write a query that returns:

COLOR COUNT
RED   1
BLUE  1

Where only Joe’s first vote is counted?

  • 1 1 Answer
  • 1 View
  • 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-23T19:13:22+00:00Added an answer on May 23, 2026 at 7:13 pm

    You would get the lowest ORDER value for each USER, and then join that against the table again to get the COLOR for those records, then group by the COLOR to count them:

    select y.COLOR, count(*) as COUNT
    from (select USER, min(ORDER) as ORDER from TheTable group by USER) x
    inner join TheTable y on x.USER = y.USER and x.ORDER = y.ORDER
    group by COLOR
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assuming an InnoDB table, will the following command ... CHECK TABLE table_name; ... cause
Assuming the following domain entity : public enum Role { User = 0, Moderator
Assuming I have the following two JQuery functions - The first, which works: $(#myLink_931).click(function
Assuming A.sql contains the following code, then second Select query won’t be executed due
Assuming I have the following schema table A: ID int primary key value varchar(255)
The title doesn't describe this very well, but assuming the following simplified table in
Assuming you have the following database table: create table Names ( Id INT IDENTITY
I have following table CREATE TABLE User ( email sysname NOT NULL, sign varbinary(256)
Assuming that we have the following table: Person: PersonID, Name, Age, Gender And we
Assuming you have a simple table like the following: +---------+---------------------+ | user_id | activity_date

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.