我在尝试加入这两个表时遇到此错误
发生数据库错误错误号:1064
错误:
您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 靠近'order,customer WHERE order.customer_id = customer.customer_id'at 第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 \ compulectronix2 \ system \ database \ DB_driver.php Line 数量:330
答案 0 :(得分: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
答案 1 :(得分:1)
每种语言都有一些保留词,我们也将其称为关键词。我们无法使用这些保留字创建变量。
这里你的表名是'order',order是mysql中的一个保留字,所以它产生了错误。你有两个选择
如果您不想重命名表,请将带有表名的引号放入 并以这种方式使用
SELECT
`order`.order_id,
`order`.order_total,
customer.first_name, customer.last_name
FROM `order`, customer
WHERE `order`.customer_id=customer.customer_id
希望它会对你有所帮助。快乐的编码。
答案 2 :(得分:0)
WITH JOIN
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`;