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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:43:08+00:00 2026-06-06T17:43:08+00:00

I have two tables, images and image_data and here is an example of my

  • 0

I have two tables, images and image_data and here is an example of my image_data table.

image_id | slide_id | language_id  | type   |
101      | 1        | 1            | CQ     |
101      | 2        | NULL         | NULL   |
56       | 5        | 1            | TN     |
56       | NULL     | 2            | NULL   |

So basically, each image will have different options and I am wondering the best way to implement this.. because I have a feeling I am doing this the wrong way.

With this, I can run a query to use GROUP_CONCAT() to turn values in multiple rows into a single concatenated string.

image_id | slide_id | language_id  | type   |
101      | 1,2      | 1            | CQ     |
56       | 5        | 1,2          | TN     |

Which is fine, but the problem with the way I am doing it right now is..it seems like it will be really difficult to update the rows with my backend system.

enter image description here

So with my query, I can determine which ones to check based on the database since I have it all in one row since I concatenated it. But now it’s like.. when I go to click “Save” and update the rows, which one do I update? there can be more than 1 row of the same image id, so how would I update the right one, and so on.

If I checked off another slide for image #101 then I would need to create a new row for it. If after that I wanted to add another language_id to it, then I would need to make sure to not add a new row since one exists with a NULL value, and to just replace the NULL value with the new language id.

It just seems really complicated and there’s so many factors, that using this method is really hard to program.

What would be the best way to do this? Any suggestions are really appreciated.

Thanks!

  • 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-06T17:43:11+00:00Added an answer on June 6, 2026 at 5:43 pm

    What you need to do is implement N:M (many-to-many) relationships between your images and slides / languages / types tables so that your design is more normalized (one fact in one place).

    Think of it this way: one image can have multiple slides, and one slide may be an option of multiple images. — this is a N:M relationship. Same goes for languages and types.

    What you need to do is get rid of your image_data table which houses the options between ALL entities and have three separate cross-reference tables instead. Here’s how you would model it:


    Base tables:

    images(image_id [PK], …)

    slides(slide_id [PK], slide_name, …)

    languages(language_id [PK], language_name, …)

    types(type_name [PK], …)

    Cross-Reference tables:

    images_has_slides(image_id [PK], slide_id [PK])

    images_has_languages(image_id [PK], language_id [PK])

    images_has_types(image_id [PK], type_name [PK])

    How it would look in ER:

    Many-To-Many ER Diagram

    With this type of design, you wouldn’t have to deal with NULL values or figuring out which row to update because you now have just one fact in one place. To get all options, you would still have to do GROUP_CONCAT() like so:

    SELECT
        a.*,
        GROUP_CONCAT(c.slide_name) AS slides,
        GROUP_CONCAT(e.language_name) AS languages,
        GROUP_CONCAT(f.type_name) AS types
    FROM
        images a
    LEFT JOIN
        images_has_slides b ON a.image_id = b.image_id
    LEFT JOIN
        slides c ON b.slide_id = c.slide_id
    LEFT JOIN
        images_has_languages d ON a.image_id = d.image_id
    LEFT JOIN
        languages e ON d.language_id = e.language_id
    LEFT JOIN
        images_has_types f ON a.image_id = f.image_id
    GROUP BY
        a.image_id
    

    Then to update image options, you would use INSERT and DELETE on the cross-reference tables:

    Let’s say you wanted to add two languages to an image, you would do

    INSERT INTO images_has_languages (image_id, language_id) 
    VALUES (101, 4), (101, 5);
    

    The above query adds languages with id’s of 4 and 5 to the image that has an id of 101.

    To remove options (unchecking on the form) – let’s say you wanted to remove 2 slides from an image

    DELETE FROM images_has_slides WHERE image_id = 101 AND slide_id IN (3,6)
    

    This removes slides with id’s of 3 and 6 from the image that has an id of 101.

    So in your application, you could figure out if you need to do insert/delete queries based on if the user unchecked or checked values in the form for the image.

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

Sidebar

Related Questions

Basically I have a database with two tables, that is, Updates table and Images
I have two tables, content and images (and a ContentImages table for the one
I have two tables images2 and image_data So the goal is to have 1
If we have two tables, say; users, and images, how do we select users
I have two tables: table a ida valuea 1 a 2 b 3 c
So here's my problem. I have two tables, photos and users_homepage_photos . In my
I have two tables, users and images which need to be joined. there is
I have two tables like so; id_image foo bar 1 3 5 2 8
I have a table which has two text boxes and an image beside it
I have two tables 1.Products prod_id prod_name 1 honda 2 hero 3 marcedes 4

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.