MySQL Procedure子查询Join

时间:2017-05-22 01:48:47

标签: mysql join subquery

我一直在尝试调试此代码,我不确定问题是什么。查看大量示例,表单和语法是正确的。我错过了什么?

BEGIN 
   SELECT *
   FROM items 
   WHERE 
      FIND_IN_SET( i_Name, wordArray ) 
   OR 
      FIND_IN_SET( i_Desc, wordArray ) 
   OR 
      ( a_ID IN (
          SELECT it.a_ID 
          FROM item_tags AS it 
          LEFT JOIN tags AS t ON it.tag_ID = t.tag_ID
          WHERE t.tag_Title IN wordArray
      ) AND i_Name IN (
          SELECT it.i_Name
          FROM item_tags AS it 
          LEFT JOIN tags AS t ON it.tag_ID = t.tag_ID 
          WHERE t.tag_Title IN wordArray) 
      );
END

这应该是一个搜索过程,它检查项目名称和描述以及标记表。
Tag_ID都是INT长度6,而wordArray是VARCHAR长度255.
Item_tags具有来自项目表的主键和来自标签表的主键。

Phpmyadmin显示的完整错误如下:
以下查询失败:

"CREATE DEFINER=`root`@`localhost` PROCEDURE `findItem`(IN `wordArray` VARCHAR(255)) NOT DETERMINISTIC CONTAINS SQL SQL SECURITY DEFINER BEGIN SELECT * FROM items WHERE FIND_IN_SET( i_Name, wordArray ) OR FIND_IN_SET( i_Desc, wordArray ) OR ( a_ID IN ( SELECT it.a_ID FROM item_tags AS it LEFT JOIN tags AS t ON it.tag_ID = t.tag_ID WHERE t.tag_Title IN wordArray ) AND i_Name IN ( SELECT it.i_Name FROM item_tags AS it LEFT JOIN tags AS t ON it.tag_ID = t.tag_ID WHERE t.tag_Title IN wordArray) );; END"
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 'wordArray ) AND i_Name IN ( SELECT it.i_Name FROM i' at line 13

0 个答案:

没有答案