2012-08-12 65 views
3

如何才能在Sqlite中獲得Nemayeh.Nemayeh字段的第10條記錄?如何在sqlite中獲得10條連接表的第一條記錄?

SELECT 
    Keyword, 
    Nemayeh.Nemayeh 

FROM 
    (SELECT 
    Keyword.Id, 
    Keyword.Keyword 
    FROM Keyword 
    ORDER BY Keyword.Keyword ASC 
    LIMIT 10 OFFSET 0 
) AS tmp 

INNER JOIN KeyWord_Nemayeh 
     ON KeyWord_Nemayeh.Id_Keyword = tmp.Id 

INNER JOIN Nemayeh 
     ON Nemayeh.Id = KeyWord_Nemayeh.Id_Nemayeh 

ORDER BY 1,2 

例如:

Key1 Nem1_1 
Key1 Nem1_2 
Key1 Nem1_3 
. 
. 
. 
Key1 Nem1_10 
Key2 Nem2_1 
Key2 Nem2_2 
. 
. 
. 
Key2 Nem2_10 
+0

所以你想要一個結果表,它至少有10個,但不超過10 ** **不同** Nemayeh.Nemayeh值? (追加'LIMIT 10'到你的查詢將太簡單了:) – biziclop 2012-08-12 12:35:58

回答

2

這差不多就是biziclop說,但應該工作。

SELECT 
    Keyword, 
    Nemayeh.Nemayeh 
FROM 
    (SELECT Keyword.Id,Keyword.Keyword 
    FROM Keyword 
    ORDER BY Keyword.Keyword ASC 
    LIMIT 10 OFFSET 0) AS tmp 

INNER JOIN KeyWord_Nemayeh ON KeyWord_Nemayeh.Id_Keyword = tmp.Id 

INNER JOIN Nemayeh ON Nemayeh.Id = KeyWord_Nemayeh.Id_Nemayeh 

ORDER BY 1,2 LIMIT 0, 10 
+0

我得到10'關鍵字',那麼我想得到10'Nemayeh'爲每個「關鍵字」。請參閱我的編輯帖子。 – 2012-08-13 06:51:29

+0

好吧,我明白了......我試圖查找,如果你可以在SQLite中創建函數,但我沒有找到關於此的任何信息。否則,我認爲你想在sqlite中很難實現。 – 2012-08-13 11:19:08

1

嘗試:

SELECT TOP 10 Keyword,... FROM... 
+0

這是錯誤的,我不能在sqlite中使用top! – 2012-08-12 12:06:16

+0

行,對不起:) http://stackoverflow.com/questions/2728999/how-to-get-top-5-records-in-sqlite – Auris 2012-08-12 15:58:54

相關問題