0

我正在尝试使用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在此查询中正确使用?

4

2 回答 2

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} 
于 2012-09-19T05:00:14.987 回答
1

你几乎就在那里 - 你只是把 ORDER 和 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} 
于 2012-09-19T05:02:02.117 回答