我有一個類似的表結構的SQLite數據庫顯示相關值,與LANID是一個FK到另一個表:SQL查詢在相同的列單獨的列
ID LANID TEXT
-------------------------
1 101 Issue1
1 102 Comment1 for Issue1
2 101 Issue2
2 102 Comment1 for Issue2
3 101 Issue3
3 102 Comment1 for Issue3
1 102 Comment2 for Issue1
...
我想取從文本字段共享相同的ID值,使用的查詢是這樣的:
SELECT t.TEXT as issue, s.TEXT as comment
FROM MyTable as t, MyTable as s
WHERE t.LANID = '101' and s.LANID = '102' AND t.ID = s.ID
AND t.TEXT like "%some text in Issue1%"
它幾乎工作,但有一個問題:它不能在需要的時候「重複」值。換句話說,我不能顯示第二個評論像這樣的問題:
issue comment
---------------------------------
Issue1 Comment1 for Issue1
Issue1 Comment2 for Issue1
...
在此先感謝您的任何提示。
作品http://sqlfiddle.com/#!7/cdd38/6 – Justin 2013-03-25 21:38:06