我正在尝试使用ORDER BY
对查询进行排序,但它声称存在语法错误。在尝试排序之前,我的查询看起来像这样:
SELECT u.*, s.*
FROM bands u
inner join statuses s on u.status_id = s.id
WHERE u.status_id = 1
LIMIT {$startpoint}, {$limit}
我尝试过像这样添加ORDER BY
,但似乎不正确:
SELECT u.*, s.*
FROM bands u
inner join statuses s on u.status_id = s.id
WHERE u.status_id = 1
LIMIT {$startpoint}, {$limit} ORDER BY u.status_id
如何在此查询中正确使用ORDER BY
?
答案 0 :(得分:1)
ORDER BY
子句出现在LIMIT
SELECT u.*, s.*
FROM bands u
inner join statuses s on u.status_id = s.id
WHERE u.status_id = 1
ORDER BY u.status_id
LIMIT {$startpoint}, {$limit}
答案 1 :(得分:1)
你几乎就在那里 - 你的命令和限制是错误的:
SELECT
u.*, s.*
FROM
bands u inner join statuses s on u.status_id = s.id
WHERE
u.status_id = 1
ORDER BY u.status_id
LIMIT {$startpoint}, {$limit}