jwwceo Posted November 20, 2007 Share Posted November 20, 2007 I am trying to write a JOIN query but it doesn't seem to be working. I get error, #1109, saying that one of my tables doesn't exist. Plus, once I get this working, I am a but confused how I can pass a criteria into this query since I am assuming that would also be done in the WHERE clause. Best, James SELECT xcart_variants.color_id FROM xcart_variants WHERE xcart_class_options.optionname xcart_variants.variantid = xcart_variant_items.variantid AND xcart_variant_items.optionid = xcart_class_options.optionid Link to comment https://forums.phpfreaks.com/topic/78117-tricky-little-query/ Share on other sites More sharing options...
roopurt18 Posted November 20, 2007 Share Posted November 20, 2007 SELECT v.`color_id` FROM `xcart_variants` v INNER JOIN `xcart_variant_items` i ON v.`variantid`=i.`variantid` INNER JOIN `xcart_class_options` o ON i.`optionid`=o.`optionid` WHERE o.optionname='some option' Link to comment https://forums.phpfreaks.com/topic/78117-tricky-little-query/#findComment-395322 Share on other sites More sharing options...
jwwceo Posted November 20, 2007 Author Share Posted November 20, 2007 I am getting this error: #1054 - Unknown column 'o.optionname' in 'where clause' Any idears?? Link to comment https://forums.phpfreaks.com/topic/78117-tricky-little-query/#findComment-395329 Share on other sites More sharing options...
jwwceo Posted November 20, 2007 Author Share Posted November 20, 2007 SOLVED. I had a variable named wrong...THANKS!!!!!!! Link to comment https://forums.phpfreaks.com/topic/78117-tricky-little-query/#findComment-395331 Share on other sites More sharing options...
jwwceo Posted November 20, 2007 Author Share Posted November 20, 2007 How would I modify this to be an UPDATE query??? I Link to comment https://forums.phpfreaks.com/topic/78117-tricky-little-query/#findComment-395345 Share on other sites More sharing options...
roopurt18 Posted November 20, 2007 Share Posted November 20, 2007 What do you want to update? Link to comment https://forums.phpfreaks.com/topic/78117-tricky-little-query/#findComment-395347 Share on other sites More sharing options...
jwwceo Posted November 20, 2007 Author Share Posted November 20, 2007 I'm looking to update "color.id". Sorry if this seems really simple...but I'm never seen queries with the little variables in them before... James Link to comment https://forums.phpfreaks.com/topic/78117-tricky-little-query/#findComment-395348 Share on other sites More sharing options...
roopurt18 Posted November 20, 2007 Share Posted November 20, 2007 Do you mean color.id or color_id? There is a big difference. UPDATING and SELECTING are two different things. Are you trying to run a single query to update color_id in multiple tables? If so, which tables do you want to update? Link to comment https://forums.phpfreaks.com/topic/78117-tricky-little-query/#findComment-395381 Share on other sites More sharing options...
jwwceo Posted November 21, 2007 Author Share Posted November 21, 2007 Sorry for the confusion. I am looking to update color_id in one table... so instead of selecting it...I want to update it... Link to comment https://forums.phpfreaks.com/topic/78117-tricky-little-query/#findComment-395531 Share on other sites More sharing options...
roopurt18 Posted November 21, 2007 Share Posted November 21, 2007 Well in which table? What do you want to update it to? And with what criteria do you wish to choose which one to update? All of that is sort of important information in solving the problem. Link to comment https://forums.phpfreaks.com/topic/78117-tricky-little-query/#findComment-395698 Share on other sites More sharing options...
jwwceo Posted November 21, 2007 Author Share Posted November 21, 2007 To simplify the problem, we want to change a hex color value in a table based on the text value (ie. Black) that is in another table. These tables do not relate to one another, except through a third table. The table/field we are trying to update is: xcart_variants.color_id based on criteria in this table: class_options.optionname The value we wish to change it to will change from time to time, so for purposes of this thread, I suppose we can just use a variable "FFFFFF". Best, James Link to comment https://forums.phpfreaks.com/topic/78117-tricky-little-query/#findComment-395773 Share on other sites More sharing options...
jwwceo Posted November 21, 2007 Author Share Posted November 21, 2007 In addition to my last post...this is what I have been trying and getting errors on: UPDATE xcart_variants SET color_id ='ffffff' INNER JOIN xcart_variant_items.variantid ON xcart_variants.variantid INNER JOIN xcart_class_options.optionid ON xcart_variant_items.optionid WHERE xcart_class_options.option_name = 'Black' Link to comment https://forums.phpfreaks.com/topic/78117-tricky-little-query/#findComment-395784 Share on other sites More sharing options...
fenway Posted November 21, 2007 Share Posted November 21, 2007 Where's the first table? Link to comment https://forums.phpfreaks.com/topic/78117-tricky-little-query/#findComment-395829 Share on other sites More sharing options...
jwwceo Posted November 21, 2007 Author Share Posted November 21, 2007 Similarly, the table I am trying to update is xcart_variants, with the field being color_id. Link to comment https://forums.phpfreaks.com/topic/78117-tricky-little-query/#findComment-395860 Share on other sites More sharing options...
fenway Posted November 21, 2007 Share Posted November 21, 2007 I've addressed the problem in your other duplicate thread. Link to comment https://forums.phpfreaks.com/topic/78117-tricky-little-query/#findComment-396012 Share on other sites More sharing options...
Recommended Posts