我有这个查询工作正常:
SELECT p.design_id, p.product_id, t.account_id, p.name, p.width, p.height,
p.price, t.email
FROM designs AS p
INNER JOIN ( SELECT user_id, email, account_id FROM users ) AS t
USING(user_id) ORDER BY p.design_id LIMIT 0, 300 );
现在我正试图修剪结果:
SELECT p.design_id, p.product_id, t.account_id, p.name, p.width,
p.height, p.price, t.email
FROM designs AS p
INNER JOIN ( SELECT user_id, email, account_id FROM users
WHERE account_id = 0) AS t
USING(user_id) ORDER BY p.design_id LIMIT 0, 3 );
但第二个查询结果与第一个完全相同。
请有人对此有所了解吗?
// UPDATE
我删除了php vaiables以阻止不必要的混淆:)
答案 0 :(得分:2)
为什么不尝试在where where条件下使用占位符,如下所示,或者是拼写错误。
"SELECT p.design_id, p.product_id, t.account_id, p.name, p.width, p.height, p.price, t.email
FROM designs AS p
INNER JOIN ( SELECT user_id, email, account_id FROM users WHERE account_id = **".$ind."**) AS t
USING(user_id) ORDER BY p.design_id LIMIT ".$from.", ".$howMany );
答案 1 :(得分:2)
尝试一下
"SELECT p.design_id, p.product_id, t.account_id,
p.name, p.width, p.height, p.price, t.email
FROM designs AS p
INNER JOIN users AS t
ON p.user_id = t.user_ID AND
t.account_id = $ind
ORDER BY p.design_id LIMIT " . $from . ", " . $howMany
答案 2 :(得分:2)
您尚未从设计中选择 user_id 列。你的JOIN根本不起作用。从手册:
USING(column_list)子句指定两个表中必须存在的列的列表。
或者所有用户都有account_id = 0(或至少所有有设计的用户)。
如果不是那些,请尝试在嵌套选择表't'之前删除单词'AS'。
您也可以在没有使用的情况下尝试使用“ON t.user_id = p.user_id”而不是“USING(user_id)”