从两个表中选择时,mysql限制错误

时间:2012-11-23 07:46:22

标签: php mysql

尝试为此sql添加限制,它在限制之前工作正常,但是一旦我添加限制,我就会收到错误消息

您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在第1行的“LIMIT 0,10”附近使用正确的语法

我的sql是

SELECT a.id,a.product_name,a.product_price,a.user_id as product_user_id,b.id as user_id,b.first_name, FROM products as a, customers as b where a.user_id=b.id and a.product_featured='Y' and a.product_status='Active' order by a.id desc limit 0,6

4 个答案:

答案 0 :(得分:1)

您的查询错误不在限制范围内,但在关键字FROM之前您输入了逗号,。删除它,您的查询将运行。

您的查询是

SELECT a.id,a.product_name,a.product_price,a.user_id as product_user_id,b.id as user_id,b.first_name, FROM products as a, customers as b where a.user_id=b.id and a.product_featured='Y' and a.product_status='Active' order by a.id desc limit 0,6

Chagne it to

SELECT a.id,a.product_name,a.product_price,a.user_id as product_user_id,b.id as user_id,b.first_name FROM products as a, customers as b where a.user_id=b.id and a.product_featured='Y' and a.product_status='Active' order by a.id desc limit 0,6

在关键字,之前删除FROM

答案 1 :(得分:0)

您已将逗号放在错误的位置删除它并执行查询:

SELECT a.id,a.product_name,a.product_price,a.user_id AS product_user_id,b.id AS user_id,b.first_name**,** FROM products AS a, customers AS b WHERE a.user_id=b.id AND a.product_featured='Y' AND a.product_status='Active' ORDER BY a.id DESC LIMIT 0,6

答案 2 :(得分:0)

只需删除From关键字之前的逗号即可。

正确的查询将是

SELECT a.id,a.product_name,a.product_price,a.user_id as product_user_id,b.id as user_id,b.first_name FROM products as a, customers as b where a.user_id=b.id and a.product_featured='Y' and a.product_status='Active' order by a.id desc limit 0,6

答案 3 :(得分:0)

解决了它,没有意识到已经添加了限制