2011-12-09 41 views

回答

3

您可以使用subquery這樣的: -

select userid, username 
from 
(
    SELECT userid,username FROM table1 ORDER BY userid DESC LIMIT 15 
) as last_15 
order by username; 
0

怎麼是這樣的:

SELECT用戶名,用戶ID FROM表1 WHERE用戶ID IN(SELECT用戶ID FROM表1 ORDER BY用戶ID DESC LIMIT 15)ORDER BY用戶名ASC

0

您可以將原來的SELECT換成新的SELECT

SELECT userid,username FROM (
    SELECT userid,username FROM table1 ORDER BY userid DESC LIMIT 15 
) ORDER BY username ASC 

或者由於數據非常簡單,您可以將原始結果加載到PHP中的數組中並對數組進行排序。

0

你可以試試這個

SELECT userid,username FROM table1 ORDER BY username ASC LIMIT 15,0 
0
select last_15.userid, last_15.username 
from 
(
    SELECT userid,username FROM table1 ORDER BY userid DESC LIMIT 15 
) as last_15 
order by last_15.username; 

這個查詢將運行,即使快速