DECLARE @item TABLE
(
IDItem int
)
DECLARE @comment TABLE
(
IDComment int,
DatePublished date,
IDItem int,
Comment varchar(100)
)
INSERT INTO @item (IDItem) VALUES (1);
INSERT INTO @item (IDItem) VALUES (2);
INSERT INTO @item (IDItem) VALUES (3);
INSERT INTO @item (IDItem) VALUES (4);
INSERT INTO @comment (IDComment, DatePublished, IDItem, Comment) VALUES (1,'2011-01-01', 1, 'test1');
INSERT INTO @comment (IDComment, DatePublished, IDItem, Comment) VALUES (2,'2011-01-02', 1, 'test2');
INSERT INTO @comment (IDComment, DatePublished, IDItem, Comment) VALUES (3,'2011-01-01', 2, 'test3');
INSERT INTO @comment (IDComment, DatePublished, IDItem, Comment) VALUES (4,'2011-01-03', 2, 'test4');
INSERT INTO @comment (IDComment, DatePublished, IDItem, Comment) VALUES (5,'2011-01-02', 3, 'test5');
INSERT INTO @comment (IDComment, DatePublished, IDItem, Comment) VALUES (6,'2011-01-05', 3, 'test6');
SELECT i.IDItem, (SELECT TOP 1 c.Comment FROM @comment c WHERE c.IDItem = i.IDItem ORDER BY c.DatePublished) FROM @item i
ВОЗВРАЩАЕТСЯ
1 test1
2 test3
3 test5
4 NULL
Если это то, что вы ищете, просто mysql этот код.Замените TOP 1 на LIMIT 1 и т. Д.