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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:32:32+00:00 2026-06-12T09:32:32+00:00

Hi all! I have a database table that looks somewhat like this (stripped for

  • 0

Hi all!

I have a database table that looks somewhat like this (stripped for the sake of clarity):

customer
====================
 name    |    track
====================
 John    |    one
 Sue     |    two
 Greg    |    one
 Loreen  |    three
 Niles   |    two

Now, I would like to generate a new color for each unique track by my select statement, something like:

SELECT name, track, ('#' || HEX(RANDOMBLOB(3))) AS color
FROM customer;

Unfortunately I can’t modify the table content or the database structure, hence, I’m forced to generate the colors on the fly. The above SELECT query produces something like this:

 name    |    track    |    color
====================================
 John    |    one      |    #000000
 Sue     |    two      |    #444444
 Greg    |    one      |    #888888
 Loreen  |    three    |    #CCCCCC
 Niles   |    two      |    #FFFFFF

i.e. a new color for each row. But that is not what I want! I want all unique tracks to keep the same color, like so:

 name    |    track    |    color
====================================
 John    |    one      |    #000000
 Sue     |    two      |    #444444
 Greg    |    one      |    #000000
 Loreen  |    three    |    #888888
 Niles   |    two      |    #444444

i.e. all ‘one’ tracks should have the ‘#000000’ color, all ‘two’ tracks should have the ‘#444444’ color and so on.

As mentioned before I don’t have the luxury of altering the database, I can only query it. Also: it’s an SQLite database running on an Android device, so I can’t afford those hairy server-side queries either.

My efforts so far:

I have come up with the following query so far:

SELECT a.name, a.track, b.color
FROM 'customer' AS a
LEFT JOIN (
    SELECT track, ('#' || HEX(RANDOMBLOB(3))) AS color
    FROM 'customer'
    GROUP BY track) AS b
ON (b.track == a.track);

But that query is bordering to what I’m allowed to do technically and what I am willing to do architecturally. The changes to the code-base required to make such a query in a well defined way is almost more expensive than the result of it would be worth.

So, what say ye, fellow architects? How can I make this as efficiently as possible?

  • 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-12T09:32:32+00:00Added an answer on June 12, 2026 at 9:32 am

    Why not just create a class that will maintain unique colors per input and have it persist it’s settings through another table or just on the harddisk?

    If you really can’t modify the database then I think creating an sql statement that will add colors will just complicate things. What happens when someone says two colors are too similar so they want you to vary them more? It will be easier to manage that in just another class

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database table that looks like this: CREATE TABLE IF NOT EXISTS
I have an in-memory table that might looks something like this: Favorite# Name Profession
I have a table in my database that looks like this. id count -----------
I have a database table that looks like this: | ID | TITLE |
I have a table that looks like: AccountType ID Name Property1 Property2 Property3 On
I have a table in SQL Server 2008 that looks kind of like this:
I have a table that looks something like this: pageload --pageloadid (autoincrementing numeric id
I am working with a legacy database schema that looks like this: product_table table
I have a database that essentially looks like this: id uniqueidentifier NOT NULL data
Let's say I have a table called my_table that looks like this: id |

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.