1
這裏的表結構:我如何申請限制這個父/子樹如表查詢
CREATE TABLE `message` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`uid` int(11) NOT NULL,
`from_uid` int(11) NOT NULL,
`content` varchar(300) NOT NULL,
`parent` int(11) DEFAULT NULL,
`create_time` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `uid` (`uid`),
KEY `from_uid` (`from_uid`),
KEY `parent` (`parent`),
CONSTRAINT `message_ibfk_1` FOREIGN KEY (`uid`) REFERENCES `u
ser` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `message_ibfk_2` FOREIGN KEY (`from`) REFERENCES `user
` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `message_ibfk_3` FOREIGN KEY (`parent`) REFERENCES `message` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8 |
這是一個表來存儲用戶的郵件和答覆。如果我對整個查詢應用一個限制,讓我們假設限制爲30,則結果將是包含父消息和子消息(答覆)的30行。但是,如何獲得每條消息的回覆30條父消息?
如果您將限制* *什麼整個查詢?告訴我們你的代碼。 – 2011-12-15 21:21:40