这个MySQL查询出了什么问题?
$result = mysql_query("SELECT did FROM publications where group IN
(SELECT s_group FROM subscriptions where uid1='$id')") or die(mysql_error());
我收到语法错误:
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 's_group FROM
subscriptions where uid1='34846')' at line 1
答案 0 :(得分:3)
GROUP
是保留关键字。围绕`将表示它是一个列名:
SELECT did FROM publications where `group` IN
(SELECT s_group FROM subscriptions where uid1=1)
答案 1 :(得分:1)
你必须编写像group
这样的“group”列,因为关键字组是MySQL中的保留关键字。
$result = mysql_query("SELECT did FROM publications where `group` IN
(SELECT s_group FROM subscriptions where uid1='$id')") or die(mysql_error());
或者您可以使用别名
$result = mysql_query("SELECT did FROM publications p where p.group IN
(SELECT s_group FROM subscriptions where uid1='$id')") or die(mysql_error());
答案 2 :(得分:0)
按照@paulius的说法检查,然后检查uid1的数据类型(如果是数字),而不是从$ id中删除引号