Php 从两个表中选择时出现mysql限制错误
尝试向该sql添加限制时,它在限制之前工作正常,但一旦添加限制,就会出现一个错误,显示 您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以了解第1行“LIMIT 0,10”附近使用的正确语法 我的sql是Php 从两个表中选择时出现mysql限制错误,php,mysql,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 wher
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
您在错误的位置放置了逗号,请将其删除,然后执行查询:
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
查询错误不在limit中,但在关键字
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
切尼
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
从中删除
,
关键字之前的,
只要从关键字中删除之前的逗号,它就会工作
正确的查询将是
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
解决了它,我没有意识到已经添加了限制您的查询显示“限制0,6”,但您的错误显示“限制0,10”。这是一个输入错误还是来自另一个查询?不是输入错误,我注意到,出于某种原因,我将其视为mysql的一般错误,但现在我认为这是不对的,一定是我正在使用的数据库类中的某个东西。这是如何解决的?您在查询中有一个错误。在
中的keword之前,您放置了一个逗号。我被问到这个问题是如何解决的。