ok, I have the following.
it gives the following error:
I have checked a rechecked the table and row names and I think they are all correct.
Can anyone see what I am doing wrong? I am trying to find all recipies that use an item with a partial name of Book of Wood Elven Culture.
this takes a spread across 3 tables.
simplfied table structure: (simplified to only what is important for this query)
I ran
by itself and got a good query. Maybe I am using the nested selects incorectly?
Basically I am going to want to update a column in all recipes rows that match the inner query, I am doing the big select to confirm that I have all the correct stuff before I make the update.
I.E. eventually I want
but I want to confirm BEFORE I actually take that step.
Code:
SELECT items.item_name, items.item_id, recipes.recipe_id FROM `recipes` WHERE recipes.item_id = items.item_id AND recipes.recipe_id IN ( SELECT recipe_components_map.recipe_id FROM recipe_components_map, items WHERE items.item_id = recipe_components_map.item_id AND items.item_name LIKE "%Book of Wood Elven Culture%" )
Code:
MySQL said: #1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT recipe_components_map.recipe_id FROM recipe_components_
Can anyone see what I am doing wrong? I am trying to find all recipies that use an item with a partial name of Book of Wood Elven Culture.
this takes a spread across 3 tables.
- items and recipies are linked by item_id. (in the recipes table) This item_id is teh result of the recipe.
- the name of an item is only in the items table.
- recipe_components_map links recipies and items. I.E. is is the "relation" table between the two. it consists of a recipe_id and an item_id (and an ammount, but that is not important to this). it is a many to many relationship.
simplfied table structure: (simplified to only what is important for this query)
Code:
-- -- Table structure for table `items` -- CREATE TABLE `items` ( `item_id` int(11) unsigned NOT NULL auto_increment, `item_name` varchar(64) NOT NULL default '', PRIMARY KEY (`item_id`), ) TYPE=MyISAM COMMENT='Everquest Items Table. Tradeskill related items only.' AUTO_INCREMENT=20312 ; -- -- Table structure for table `recipes` -- CREATE TABLE `recipes` ( `recipe_id` int(11) unsigned NOT NULL auto_increment, `item_id` int(11) unsigned NOT NULL default '0', PRIMARY KEY (`recipe_id`), KEY `item_id_IDX` (`item_id`) ) TYPE=MyISAM AUTO_INCREMENT=20472 ; -- -- Table structure for table `recipe_components_map` -- CREATE TABLE `recipe_components_map` ( `recipe_id` int(11) unsigned NOT NULL default '0', `item_id` int(11) unsigned NOT NULL default '0', `amount` tinyint(2) unsigned NOT NULL default '1', PRIMARY KEY (`recipe_id`,`item_id`) ) TYPE=MyISAM;
Code:
SELECT recipe_components_map.recipe_id FROM recipe_components_map, items WHERE items.item_id = recipe_components_map.item_id AND items.item_name LIKE "%Book of Wood Elven Culture%"
Basically I am going to want to update a column in all recipes rows that match the inner query, I am doing the big select to confirm that I have all the correct stuff before I make the update.
I.E. eventually I want
Code:
UPDATE recipes SET race = ELF WHERE recipe_id IN ( SELECT recipe_components_map.recipe_id FROM recipe_components_map, items WHERE items.item_id = recipe_components_map.item_id AND items.item_name LIKE "%Book of Wood Elven Culture%" )
Comment