英文:
Check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE order_id = 2' at line 1
问题
以下是您要翻译的内容:
错误:您的SQL语法有误;请检查与您的MariaDB服务器版本对应的手册,以找到在第1行附近使用的正确语法。
当我尝试在连接订单、用户和产品表之后获取数据时,我收到了这个错误消息。
完整查询:
SELECT O.order_id,
U.username,
P.product_name
FROM orders O
INNER JOIN users U ON O.user_id = U.user_id
INNER JOIN products P ON O.product_id = P.product_id
ORDER BY O.order_id
WHERE O.order_id = ${id}
预期输出:
{
"order_id": 1,
"username": "userrrr",
"product_name": "Test Product"
},
{
"order_id": 2,
"username": "test04",
"product_name": "Product product"
}
英文:
Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE order_id = 2' at line 1
I get this error when I'm trying to get data after joining orders, users and products table
Full query:
SELECT O.order_id,
U.username,
P.product_name
FROM orders O
INNER JOIN users U ON O.user_id = U.user_id
INNER JOIN products P ON O.product_id = P.product_id
ORDER BY O.order_id
WHERE O.order_id = ${id}
Expected output:
{
"order_id": 1,
"username": "userrrr",
"product_name": "Test Product"
},
{
"order_id": 2,
"username": "test04",
"product_name": "Product product"
}
答案1
得分: 1
where
子句应该在order by
子句之前,而不是之后:
SELECT orders.order_id, users.username, products.product_name
FROM orders
INNER JOIN users ON orders.user_id = users.user_id
INNER JOIN products ON orders.product_id = products.product_id
WHERE order_id = ${id}
ORDER BY orders.order_id
英文:
The where
clause should come before the order by
clause, not after it:
SELECT orders.order_id, users.username, products.product_name
FROM orders
INNER JOIN users ON orders.user_id = users.user_id
INNER JOIN products ON orders.product_id = products.product_id
WHERE order_id = ${id}
ORDER BY orders.order_id
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论