我正在尝试获取默认查询以在页面加载时实现,但我得到:错误:您的SQL语法中有错误;查看与您的MySQL服务器版本对应的手册,以便在'FROM artist,cakes WHERE artist.artist_id = cakes.artist_id ORDER BY artist.ar'第2行附近使用正确的语法
我对SQL很陌生,我的讲师不禁说它太复杂但没有提供进一步的解释所以我认为最好在这里问。
有问题的查询:
$q = "SELECT artist.artist_id,
CONCAT_WS(' ', artist_name) AS artist,
cake_name,
price,
description,
cake_id,
FROM artist, cakes
WHERE artist.artist_id = cakes.artist_id
ORDER BY artist.artist_name ASC,
cakes.cake_name ASC"; //getting the cakes to display in ascending order of artist then cake name
我会非常感激地收到任何有关我出错的帮助或见解,谢谢!
答案 0 :(得分:4)
你在cake_id之后得到了一个额外的逗号。
cake_id FROM artist,
答案 1 :(得分:3)
SELECT
子句末尾有一个额外的逗号,就在FROM
子句之前:
AS artist, cake_name, price, description, cake_id, FROM artist, cakes
通过以更易读的方式格式化代码,您可以更轻松地发现此类错误。像这样:
SELECT
artist.artist_id,
CONCAT_WS(' ', artist_name) AS artist,
cake_name,
price,
description,
cake_id, -- more obvious error
FROM
artist,
cakes
WHERE
artist.artist_id = cakes.artist_id
ORDER BY
artist.artist_name ASC,
cakes.cake_name ASC
答案 2 :(得分:0)
$q = "SELECT artist.artist_id, CONCAT_WS(' ', artist_name)
AS artist, cake_name, price, description, cake_id, FROM artist, cakes
^---REMOVE THIS DIRTY COMMA
答案 3 :(得分:0)
SELECT artist.artist_id
,CONCAT_WS(' ', artist_name) AS artist
,cake_name
,price
,description
,cake_id
, FROM artist, cakes
WHERE artist.artist_id = cakes.artist_id ORDER BY artist.artist_name ASC,
cakes.cake_name ASC
您在FROM前面有一个逗号。