Mysql 嵌套查询上的SQL语法错误
我正在维护一个旧网站,它在mysql查询中抛出了一些sql错误。错误如下所示Mysql 嵌套查询上的SQL语法错误,mysql,sql,Mysql,Sql,我正在维护一个旧网站,它在mysql查询中抛出了一些sql错误。错误如下所示 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 'OR syprc_serial IN (SELECT b.syprc_serial FROM syproductcategories.b WHERE
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 'OR syprc_serial IN (SELECT b.syprc_serial FROM syproductcategories.b WHERE b.syp' at line 1
我怀疑这与我的嵌套select的语法有关,尽管我还没有成功地修复它!有人知道吗
$query = "SELECT syprc_serial, syprd_serial, sypcd_description, sypdd_title, sypdd_shortdescription, sypdd_longdescription, sypdd_primarypackage, sypdd_owner, syprd_image01, syprc_subcategoryof ".
"FROM syproductcategories, syproductcategoriesdescription, syproducts, syproductsdescription ".
"WHERE syprc_serial = sypcd_productcategoryserial ".
"AND syprd_categoryserial = syprc_serial ".
"AND sypdd_languagecode = '". $_SESSION['language']."' ".
"AND sypcd_languagecode = '". $_SESSION['language']."' ".
"AND syprd_serial = sypdd_productserial ".
"AND syprc_companyserial = '" . $_SESSION['company'] ."' ".
"AND syprd_companyserial = '" . $_SESSION['company'] ."' ".
"AND syprd_active = 1 ".
"AND (syprc_serial = $syprc_serial ".
"OR syprc_serial IN (SELECT b.syprc_serial FROM syproductcategories b WHERE b.syprc_subcategoryof = $syprc_serial) ".
"OR syprc_subcategoryof IN (SELECT b.syprc_serial FROM syproductcategories b WHERE b.syprc_subcategoryof = $syprc_serial) ".
") ".
"ORDER BY syprc_serial, sypdd_title, syprd_serial";
语法在我看来很好。$\u会话['language']和$\u会话['company']中的任何内容都将放入字符串文本中。但是$syprc\U序列号不会。因此,$syprc_serial可能不包含数字
- 这应该发生:
其中b.syprc\u subcategory of=123)
- 这不是:
其中b.syprc_subcategory of=ABC)
- 这两者都不是:
其中b.syprc_subcategory of=)
- 甚至是这样:
其中b.syprc_subcategory of=(),-)代码>
像这样的事情很容易发现:打印最终声明。如果您不能立即看到问题所在,那么直接将其用于dbms。删除并添加部分,直到其正常工作。如果您只是在该行之后打印查询,您应该可以准确地看到它的外观,并且更容易检查错误。@如果没有真正的查询,我们只能推测
$syprc\u serial
的计算结果为空字符串……您在哪里定义了“b”?错误消息和查询似乎不同:“FROM syproductcategories b”不带点…@syedmohsin:typos不会给出语法错误。