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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:32:37+00:00 2026-06-03T13:32:37+00:00

I have a community driven database for an iOS game. I am trying to

  • 0

I have a community driven database for an iOS game. I am trying to aggregate the data I’ve collected by the community, and it looks something like this:

+--------+--------+--------------+
| color1 | color2 | result_color |
+--------+--------+--------------+
| red    | blue   | purple       |
| blue   | red    | purple       |
| red    | blue   | purple       |
| yellow | blue   | green        |
+--------+--------+--------------+

Currently, I am running the following query:

select
    count(*) as count,
    `Mixes`.*
from
    `mixes` AS `Mixes`
where
    `result_color` = 'purple'
group_by
    color1,
    color2
order by
    `count` desc

Which produces the following output:

+-------+--------+--------+--------------+
| count | color1 | color2 | result_color |
+-------+--------+--------+--------------+
| 2     | red    | blue   | purple       |
| 1     | blue   | red    | purple       |
+-------+--------+--------+--------------+

However, I would like it to produce the following output, since when mixing colors it doesn’t matter which color you mix first:

+-------+--------+--------+--------------+
| count | color1 | color2 | result_color |
+-------+--------+--------+--------------+
| 3     | red    | blue   | purple       |
+-------+--------+--------+--------------+

So, my question is, how can I aggregate data over 2 columns such that when color1 is red and color2 is blue, that the aggregate function treats it the same as when color1 is blue and color2 is red?

Thanks in advance!

  • 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-03T13:32:41+00:00Added an answer on June 3, 2026 at 1:32 pm

    If you just have the two color columns you can simply order them with a CASE expression:

    SELECT
      COUNT(*) AS `count`,
      CASE WHEN color1 < color2 THEN color1 ELSE color2 END AS color1,
      CASE WHEN color1 >= color2 THEN color1 ELSE color2 END AS color2,
      resultcolor
    FROM mixes
    WHERE resultcolor = 'purple'
    GROUP BY
      CASE WHEN color1 < color2 THEN color1 ELSE color2 END,
      CASE WHEN color1 >= color2 THEN color2 ELSE color1 END,
      resultcolor
    ORDER BY `count`;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database driven community web site, where users can post entries. Each
Hello, stackoverflow community! I am working on a rather large database-driven web application. The
Hi community I have the following problem, given this xml <test> <comp> <id>1</id> <content>bar</content>
I'm a developer/designer for a community driven website: http://www.thegamesdb.net The problem we have is
I have a MongoDB collection called employees where there are documents like this: {
I have eyeballing this code for a long time, trying to reducing the amount
I would like to have the community provide translations for some of my application
I have a social networking site in which we have a restricted community. When
I have a little question to community. Does ASP.NET MVC allow to execute an
I have a joomla website and I use community builder for user registration and

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.