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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:10:17+00:00 2026-06-04T16:10:17+00:00

I apologize if this is a dumb or simple question, and I have tried

  • 0

I apologize if this is a dumb or simple question, and I have tried searching for it, but was unable to find a solution; I suspect I simply don’t know the name for this kind of an operation.

I have a MySQL database with a “card” table.

Cards have a casting cost, which may contain between 0 and 5 colors. I want to update every entry in the cards table to include 5 columns, each a boolean for each of the possible colors. So I would need a short algorithm which would parse the colors in a card, then populate the 5 boolean color values accordingly.

I can imagine how to do this with a PHP script, but I thought there must be some way to do it with pure MySQL. Am I mistaken, or is there a name for this type of script?

  • 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-04T16:10:19+00:00Added an answer on June 4, 2026 at 4:10 pm

    I understand your question to mean that your card table currently has a column called casting cost that contains a set of colours, e.g. 'red,green' or 'blue,orange,yellow' and that you are looking for a query that yields boolean columns indicating whether each possible colour is in the casting cost?

    If so, MySQL’s FIND_IN_SET() function should give you what you’re after:

    SELECT *,
           FIND_IN_SET('red',    `casting cost`) > 0 AS red,
           FIND_IN_SET('blue',   `casting cost`) > 0 AS blue,
           FIND_IN_SET('green',  `casting cost`) > 0 AS green,
           FIND_IN_SET('orange', `casting cost`) > 0 AS orange,
           FIND_IN_SET('yellow', `casting cost`) > 0 AS yellow
    FROM   card
    

    If you want to permanently change the table to include such columns:

    ALTER TABLE card
      ADD COLUMN red    BOOLEAN NOT NULL DEFAULT FALSE,
      ADD COLUMN blue   BOOLEAN NOT NULL DEFAULT FALSE,
      ADD COLUMN green  BOOLEAN NOT NULL DEFAULT FALSE,
      ADD COLUMN orange BOOLEAN NOT NULL DEFAULT FALSE,
      ADD COLUMN yellow BOOLEAN NOT NULL DEFAULT FALSE
    
    UPDATE card SET
      red    = FIND_IN_SET('red',    `casting cost`) > 0,
      blue   = FIND_IN_SET('blue',   `casting cost`) > 0,
      green  = FIND_IN_SET('green',  `casting cost`) > 0,
      orange = FIND_IN_SET('orange', `casting cost`) > 0,
      yellow = FIND_IN_SET('yellow', `casting cost`) > 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I apologize that this is a dumb question, but I have been pulling my
I apologize if this question was already asked but I can't seem to find
I apologize if this is a dumb question, but hear me out: Dictionary<string, string>
I apologize in advance if this is an incredibly dumb question... Currently I have
Apologies if this is a dumb question but I'm trying to format a currency
I apologize if this a duplicate question (I didn't find anything like that). I'm
I'm new to Rails so I apologize if this is a dumb question. I
I apologize if this is a duplicate post, but I couldn't find the answer
I come from frontend background, so I apologize if this db question seems dumb.
I apologize if this question is too basic, but I just can't figure out

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.