【问题标题】:How can I fix 1064 error如何修复 1064 错误
【发布时间】:2015-06-08 15:23:58
【问题描述】:

我在尝试加入这两个表时遇到了这个错误

发生数据库错误错误号:1064

错误:

您的 SQL 语法有错误;检查手册 对应于您的 MySQL 服务器版本,以便使用正确的语法 在“订单,客户 WHERE order.customer_id=customer.customer_id”附近 第 2 行

查询:

SELECT order.order_id,order.order_total,
customer.first_name,customer.last_name FROM order, customer WHERE
order.customer_id=customer.customer_id; 

文件名:

D:\xampp\htdocs\compullectronix2\system\database\DB_driver.php 行 数量:330

【问题讨论】:

  • 尝试从 order INNER JOIN customer ON order.customer_id = customer.customer_id 执行此操作
  • 它不起作用@Miladinovic

标签: mysql phpmyadmin


【解决方案1】:

“ORDER”是 SQL 中的保留字。你必须用反引号引用它:

SELECT 
    `order`.order_id,
    `order`.order_total,
    customer.first_name, customer.last_name 
FROM `order`, customer 
WHERE `order`.customer_id=customer.customer_id 

List of reserved words

【讨论】:

    【解决方案2】:

    每种语言都有一些保留词,我们也将其称为关键字。我们不能用这些保留词创建变量。

    这里你的表名是'order',order是mysql中的一个保留字,所以它会产生en错误。你有两个选择

    1. 按照惯例,不要使用 mysql 保留字作为表名,以便您可以重命名表。
    2. 如果您不想重命名表格,请在表格名称中加上引号 并以这种方式使用

      SELECT 
          `order`.order_id,
          `order`.order_total,
          customer.first_name, customer.last_name 
      FROM `order`, customer 
      WHERE `order`.customer_id=customer.customer_id 
      

    希望对您有所帮助。编码愉快。

    【讨论】:

      【解决方案3】:

      加入

      SELECT `order`.`order_id`, `order`.`order_total`, `customer`.`first_name`, `customer`.`last_name`
      FROM `order`
      JOIN `customer` ON
      `order`.`customer_id` = `customer`.`customer_id`; 
      

      没有加入

      SELECT `order`.`order_id`, `order`. `order_total`,
      `customer`.`first_name`, `customer`.`last_name` 
      FROM `order`, `customer` 
      WHERE `order`.`customer_id` = `customer`.`customer_id`;
      

      【讨论】:

        猜你喜欢
        • 2014-06-24
        • 1970-01-01
        • 2014-07-12
        • 2014-12-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-29
        相关资源
        最近更新 更多