2013-02-13 68 views

回答

0

不知道爲什麼你需要這一點,但在這裏你去:

SELECT First, Last 
FROM (
    SELECT Name AS 'First' 
    FROM contactlist 
    ORDER BY Name ASC 
    LIMIT 1 
) t, (
    SELECT Name AS 'Last' 
    FROM contactlist 
    ORDER BY Name DESC 
    LIMIT 1 
) t2 

可能會多一點樂趣,採取一切你的名字和行號(第一ASC到DESC姓)與它們匹配 - 這樣的事情:

SELECT First, Last 
FROM (
    SELECT Name AS 'First', 
    @rowNum:[email protected] + 1 rn 
    FROM contactlist 
    JOIN (SELECT @rowNum:= 0) r 
    ORDER BY Name ASC 
) t JOIN 
(
    SELECT Name AS 'Last', 
    @rowNum2:[email protected] + 1 rn 
    FROM contactlist 
    JOIN (SELECT @rowNum2:= 0) r 
    ORDER BY Name DESC 
) t2 ON t.rn = t2.rn 

和一些Fiddle

相關問題