我的問題是這樣的:依賴MySQL的SELECT
我的表是MESSAGE
和MESSAGE_COMMENT
,
MESSAGE (id,content)
MESSAGE_COMMENT (id, message_id, content)
,我需要選擇所有消息和最多3條評論每封郵件,就像在這個例子:
type | id | content
M 15 "this is a message with no comments"
M 16 "this is another message with many comments"
R 16 "comment1"
R 16 "comment2"
R 16 "comment3"
M 17 "this is another message with no comments"
「id」是MESSAGE.id
當它是一條消息,COMMENT.message_id
當它是一條評論。
我希望我已經解釋清楚我的問題..
評論可以以任意順序排列,還是按id排序? – 2010-01-27 12:29:35
你是否真的需要你的查詢來在不同的表/列中包含像這樣的'content'字段中的值?如果你的郵件內容和評論內容的返回數據中有不同的列,你可以編寫一個更簡單的SQL查詢。 – 2010-01-27 12:49:43