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

  • Home
  • SEARCH
  • 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 8783349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:48:38+00:00 2026-06-13T20:48:38+00:00

My question might be dumb since I think it’s a very common design issue,

  • 0

My question might be dumb since I think it’s a very common design issue, and I guess there is a simple and usual solution to it:

  • I have a table Producer and a table Movie
  • ONE Producer has produced MANY Movies
  • ONE Producer has ONE favorite Movie among the ones he has produced

How do I implement this in MySQL?

  1. just one ONE-TO-MANY relation between Producer and Movie, plus a ‘favorite’ boolean attribute in the Movie table
  2. one ONE-TO-MANY relation to represent the ‘has produced’ relation, and a ONE-TO-ONE relation to represent the ‘is favorite’ relation

The first solution seems more natural to me, but when the producer wants to change his favorite movie, I guess the second solution is more efficient. As well as it should be more efficient to find a producer’s favorite movie with solution #2.

What am I missing? Is there a best solution? If not in which case should I use solution #1 and solution #2?

(Of course, my problem is a bit more complex thant the example above…)

  • 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-13T20:48:39+00:00Added an answer on June 13, 2026 at 8:48 pm

    The (1) is not easy/efficient to enforce declaratively. Plus, you end-up wasting space on all non-favorite movies.

    The (2) is the way to go. Unfortunately, this circular dependency will lead to the chicken-and-egg problem, which is solved:

    • either by deferring one of the FKs (if the DBMS supports it, which MySQL unfortunately desn’t),
    • or by leaving the FK in user NULL-able, which is less than ideal since the user can now have zero or one favorite movies (as opposed to strictly one).

    Assuming you want the same movie to be relatable to multiple users (making it a many-to-many relationship, not one-to-many as you stated), your model would end-up looking something like this in a DBMS supporting deferrable FKs:

    enter image description here

    But you don’t have the luxury of deferring the constraints in MySQL, so you’ll be forced to do something like this:

    enter image description here

    CHECK (FAVORITE_USER_ID IS NULL OR FAVORITE_USER_ID = USER_ID)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might sound very dumb question but I am just confused. I am quite
This might be a dumb question but I can't get this super simple script
I have a question that might seem a bit dumb since I have been
This might be (read: probably is) a dumb question, but here goes... Is there
This might be a dumb question. I think I already know the answer, just
This might be a dumb question, but I'd love to know if there was
I know you might think this is a duplicate or a dumb question. But
I am a newbie (very much so), so my question might be dumb, but
I guess for most of you this might be a dumb question, but I
This might be a dumb question. But does ADO.net support updating to a database

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.