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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:39:58+00:00 2026-06-13T08:39:58+00:00

Scenario : Multiple product images, one main image. Currently, I’ve got 2 tables to

  • 0

Scenario : Multiple product images, one main image.

Currently, I’ve got 2 tables to manage this. One for storing product images and another table for storing mainProductImageIds. In the table that stores a list of mainProductImageIds, I’ve got a unique index on prodid+isMain to enforce One Main Image Per Product Id.

My Question relates to the table below (if I was going to only use 1 table). How would I enforce 1 isMain=1 per prod? Is there any index setting that would error when I tried to set isMain=1 to image_id=2 since image=1 is already the main image? You can’t put a unique_key on prod+isMain.

|image_id |prod|isMain
|---------|----|------
|0        |1   |0
|1        |1   |1
|2        |1   |0
|3        |2   |1
|4        |3   |0
|5        |3   |1
  • 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-13T08:39:59+00:00Added an answer on June 13, 2026 at 8:39 am

    The answer, I learned, is really simple and has to do with how MySQL indexes NULL values. Over Here they talk about:

    For all engines, a UNIQUE index allows multiple NULL values for
    columns that can contain NULL.

    so as long as my isMain field allow enforces one value and NULL (maybe an ENUM), I’m all set. The unique_index will only be enforces when isMain is set to a distinct value and not when it is set to NULL.

    The Updated Table Looks like This:

    |image_id |prod|isMain
    |---------|----|------
    |0        |1   |null
    |1        |1   |1
    |2        |1   |null
    |3        |2   |1
    |4        |3   |null
    |5        |3   |1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a scenario where multiple devices are connected to one com port. Each
I have a scenario in which I have to run multiple commands one after
Another collinear-points question. This one's twist is, I'm using integer arithmetic, and I'm looking
How come python did not refer to this so basic scenario? handling multiple modules
this is the scenario: multiple web systems (mostly lampp/wampp) exist, most of them with
I know there are multiple variations of this scenario but I've struggled making it
Scenario Multiple application servers host web services written in Java, running in SpringSource dm
The Scenario: We have multiple nodes distributed geographically on which we want to have
I'm having a scenario where I had to deploy multiple directories for different languages.
Can multiple SSRS share the same DB? We're getting into an SSRS customization scenario,

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.