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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:32:04+00:00 2026-05-15T07:32:04+00:00

I want to code cleaner and more efficiently and I wanted to know any

  • 0

I want to code cleaner and more efficiently and I wanted to know any other suggestions for the following problem:

I have a mySQL database that holds data about a set of photograph names. Oh, say 100 photograph names

Table 1: (photos) has the following fields:
photo_id, photo_name

Ex data:

1 | sunshine.jpg
2 | cloudy.jpg
3 | rainy.jpg
4 | hazy.jpg
...

Table 2: (categories) has the following fields:
category_id, category_name, category_order

Ex data:

1 | Summer Shots | 1,2,4
2 | Winter Shots | 2,3
3 | All Seasons  | 1,2,3,4
...

Is it efficient to store the order of the photos in this manner per entry via comma delimited values? It’s one approach I have seen used before but I wanted to know if something else is faster in run time.

Using this way I don’t think it is possible to do a direct INNER JOIN on the category table and photo table to get a single matched list of all the photographs per category.

Ex: Summer shots -> sunshine.jpg, cloudy.jpg, hazy.jpg because it was matched against 1,2,4

The iteration through all the categories and then the photos will have a O(n^2) and there has to be a better/faster way. Please educate me 🙂

  • 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-05-15T07:32:05+00:00Added an answer on May 15, 2026 at 7:32 am

    it seems to me you could use another table for the relation between photos and categories with fields category_id, order_id and photo_id

    I think it would be simpler to use, and you’ll be able to do your join

    I would also suggest you set photo_id as an index in that new table if you decide to use that solution.

    — EDIT —

    table photo ‘photo_id’,’photo_name’

    • photo_id is a primary key, unique, with auto increment and possibly an index

    table category ‘category_id’, ‘category_name’

    • category_id is a primary key, unique(unless you want it to be possible to have different names for a same category), with auto increment and possibly an index

    table category_content ‘category_id’,’photo_id’,’order’

    • category_id is a foreign key pointing toward table category’s column category_id
    • photo_id is a foreign key pointing toward table photo’s column photo_id
    • primary key is a combined primary key between category_id and order
    • photo_id and category_id are both index

    Using ‘index’ somehow tells MySQL that you want to optimize research on the indexed columns, when you notice that many queries have WHERE and/or JOIN on specific columns, usually it is a good idea to set the column to be indexed. Also, unless it simplifies something, it’s almost never a good idea to combine multiple data into a single one like you did, an exception could be combining phone number prefix with actual number and a few things like this, but they are exeptional cases. The way you hardcoded the order within the table would have been good if you used files, but in a database, you’re better off using another table than using comma separators. Any questions?

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

Sidebar

Related Questions

In the following code I want to replace every occurrence of U.S.A with united
I am a AS3 novice learning PureMVC and want to write code following best
I was wondering if there was a more efficient (efficient as in simpler/cleaner code)
JS Fiddle (code) This is more of a task I have set myself to
What considerations do I need to make if I want my code to run
I am learning C#. I want to code an on the fly encryption program.
I often find I want to write code something like this in C#, but
I'm writing some semi-portable code and want to be able to detect when I'm
I'm overriding WndProc, so I want to write code like if (m.Msg == WM_COMMAND)
The window pops up below the variable, and obscures the code I want to

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.