View Single Post
  #1  
Old 04-05-2010, 02:23 AM
Arianna's Avatar
Arianna Arianna is offline
Dev Staff
 
Join Date: Sep 2009
Posts: 334
Gender: Female
Credits: 21,847
Arianna will become famous soon enough
Arrow Join query for optimization?

I'm trying to make so siggy.php (function getcurrentimage($id)) uses one join query.
Now, this query has been tweaked and tweaked and tweaked, but it gets too many rows from the db. My original query worked fine if it wasn't an egg, but if it was (level=0) then it selected nothing at all.
PHP Code:
SELECT *                                                                       // easy, it just selects
FROM adopts_adoptablesadopts_owned_adoptablesadopts_levels                // where it selects from
WHERE  `adopts_owned_adoptables`.`aid` = 144 AND                              // where the adoptable id is the one we want
`adopts_owned_adoptables`.`type` = `adopts_adoptables`.`type` AND             // where the adopts type is the type we select from adopts_adoptables
(`adopts_levels`.`adoptiename` = `adopts_adoptables`.`type` OR                // either    (a) the level's type name is equal to the adopt's type
`adopts_owned_adoptables`.`currentlevel` = 0) AND                            // or        (b) the adopt's current level is equal to 0
(`adopts_owned_adoptables`.`currentlevel` = `adopts_levels`.`thisislevel`    // and either    (a) the adopt's current level is the level we select from the db
 
OR `adopts_owned_adoptables`.`currentlevel` = 0)                            // or            (b) the adopt's current level is equal to 0
LIMIT 1                                                                        // we only want one adoptable 
Any idea on what I should do? I want to use a join query as these images are used so much, but it's so complicated. :P
Reply With Quote