Check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE order_id = 2' at line 1

huangapple go评论62阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年6月12日 14:11:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76453990.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定