If you refuse to alter your structure to represent a proper many to many relation, then your options are to either:
- Do as you have done and for ever result field query for primary data [not recommended]
- Inner join ever record field back to the primary table.
Code:
SELECT it1.name, it2.name, it3.name. . . .
FROM Gallery g
INNER JOIN ImageTable it1 ON it1.id = g.slide1
INNER JOIN ImageTable it2 ON it2.id = g.slide2
INNER JOIN ImageTable it3 ON it3.id = g.slide3
. . .
I don't recommend either.
Without proper normalization you will have anomalies present themselves. You will also waste a lot of space or time especially with deletion queries of the primary image table since you then need to go over every slide. You also cannot enforce uniqueness to the slides per gallery if that's what you want to do.
Either way, you're putting weight on the language to enforce something. You may as well write the proper many to many normalization in order to control the storage properly. Improper normalization is NOT easy to query properly.