On 1 May 2010 10:13, Karl DeSaulniers <karl@xxxxxxxxxxxxxxx> wrote: > What is the SQL query I can use to get an item that has two IDs? > Something to the effect of... > > $q = "SELECT OptID = '$OptID' FROM ".PRODUCT_OPTIONS." WHERE ProdID = > '$ProdID' AND OptGrpID='$OptGrpID'"; Close but no cigar. $q = "SELECT OptID FROM ".PRODUCT_OPTIONS." WHERE ProdID = '$ProdID' AND OptGrpID='$OptGrpID'"; I am assuming that you have escaped $ProdID and $OptGrpID :) > Is this correct or am I missing something? > A single group ID can have multiple option IDs set to it. > A single product ID can have multiple group IDs set to it. You're looking at a many-to-many table - a row should be unique given all three IDs. Only those three IDs together should form a unique row. > I am trying to single out a product option. > The option has a group ID and a product ID assigned to it. > I'm starting to wonder about your data model. Should options always be in groups? I'm guessing that you need one of three things: 1. Split up the product options table. A product can have some individual options and some group options - these have nothing to do with each other and you need to be able to set them without regard for each other. 2. Remove the productOptionID from the product options table. A product only has option groups, no individual options. 3. Remove the groupOptionID from the product options table. A product only has individual options, regardless of the option group these options belong to. Regards Peter -- <hype> WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 </hype> -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php