dqx24298 2013-09-20 17:15
浏览 184
已采纳

为什么这个MySQL select查询不能与WHERE子句一起使用?

Hello this is driving me crazy. I can't get this query to work with the WHERE clause. It works without it. I have tried everything. I have looked at dozens of websites and dozens of questions here. I can't see anything wrong with this query. But it gives me this error whenever I try to use a WHERE clause:

1064: 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 'WHERE `cond` = '1'' at line 4

I have tried it with spaces and without, with single quotes and without, I have tried mysqli. I just can't figure out what the problem is.

Here is the code I currently have:

 $sql = <<<SQL
    SELECT *
    FROM `master_inv`
    ORDER BY `sku`
    WHERE `cond` = '1' 
SQL;
  • 写回答

3条回答 默认 最新

  • doq1969 2013-09-20 17:17
    关注

    WHERE clause goes before ORDER BY.

    $sql = <<<SQL
              SELECT *
              FROM `master_inv`
              WHERE `cond` = '1' 
              ORDER BY `sku`
             SQL;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 comsol稳态求解器 找不到解,奇异矩阵有1个空方程返回的解不收敛。没有返回所有参数步长;pid控制
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功