为什么我不能运行这个MySQL命令?
SELECT *
FROM users
WHERE
id = 1 OR
id BETWEEN 2 AND 8
GROUP BY
username ASC
ORDER BY
username ASC
LIMIT 5
任何人都可以解释一下吗?
我收到以下错误:
ERROR 1064 (42000): You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right
syntax to use near '= 1 OR id BETWEEN 2 AND 8 GROUP BY username ASC
ORDER BY username ASC LIMIT 5' at line 1
答案 0 :(得分:2)
您缺少browse.showOpenDialog(MainForm.frame)
条款:
WHERE
您收到的错误是因为SELECT *
FROM users
WHERE id = 1 OR id BETWEEN 2 AND 8
GROUP BY username ASC
ORDER BY username ASC
LIMIT 5;
被视为id
的别名而MySQL正在期待类似users
,,
,[LEFT, RIGHT, INNER, CROSS] JOIN
的内容,WHERE
,GROUP BY
或ORDER BY
。
LIMIT
在MySQL(至少大多数版本)中是多余的,因为ORDER BY
中的ASC
进行排序(请参阅documentation)。但是,我不会依赖于此,并使用:
GROUP BY
答案 1 :(得分:1)
只需在条件之前添加where
,也可以在群组之后删除ASC,这是没有意义的:
SELECT * FROM users where id = 1
OR id BETWEEN 2 AND 8
GROUP BY user
ORDER BY user ASC LIMIT 5