title: Error 1242: Subquery Returns More Than 1 Row - why?
body: <p>I am working on a procedure which sells my items. When I try to call it, it tells me that error message. I checked which part returns more rows, but I couldn't figure it out. Here is the code for that procedure:</p>
  
  <pre><code>DELIMITER //
  CREATE PROCEDURE SellItem(pCharacterName varchar(50), pItemName varchar(50), howManyItems int(11))
  BEGIN
  
  DECLARE pchar int(11);
  DECLARE pitem int(11);
  DECLARE pitemCost int(11);
  DECLARE pcharMoney int(11);
  DECLARE newMoneyValue int(11);
  DECLARE cnt int(11) DEFAULT 1;
  DECLARE pcharitid int(11);
  
  SET pchar=(SELECT `getChar`(`pCharacterName`));
  SET pitem=(SELECT `getItem`(`pItemName`));
  SET pitemCost=(SELECT `price` FROM `item` WHERE `item`.`item_id`=pitem);
  SET pcharMoney=(SELECT `money` FROM `character` WHERE `character`.`character_id`=pchar);
  SET newMoneyValue=pcharMoney;
  WHILE cnt&lt;=`howManyItems` DO
  SET newMoneyValue=newMoneyValue+pitemCost;
  SET cnt=cnt+1;
  END WHILE;
  SET cnt=1;
  
  WHILE cnt&lt;=`howManyItems` DO
  SET pcharitid=(SELECT MAX(`character_item_id`) FROM `character_item` WHERE `character_item`.`character_id`=pchar AND `character_item`.`item_id`=pitem);
  IF (SELECT `item_id` FROM `character_item` WHERE `character_item`.`item_id` IN(SELECT `item_id` FROM `item` WHERE `item`.`name`=`pItemName`)) THEN
  DELETE FROM `character_item` WHERE `character_item`.`character_item_id`=pcharitid;
  UPDATE `character` SET `money`=newMoneyValue WHERE `character`.`character_id`=pchar;
  SET cnt=cnt+1;
  END IF;
  END WHILE;
  END; //
  DELIMITER ;
  </code></pre>
  
  <p>The functions I call are simple functions which return me the ID of the selected character/item.</p>