View Single Post
Old 12-05-2012, 11:20 PM   PM User | #8
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
If you refuse to alter your structure to represent a proper many to many relation, then your options are to either:
  1. Do as you have done and for ever result field query for primary data [not recommended]
  2. 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.

Last edited by Fou-Lu; 12-05-2012 at 11:50 PM..
Fou-Lu is offline   Reply With Quote