setup:
create table main(id integer unsigned);
create table test(id integer unsigned,created datetime,text text);
insert into main value(1);
insert into test value(1,now(),'something1');
insert into test value(1,now() + interval 1 day,'something2');
Using:
select main.id, text from main left join test on main.id=test.id
group by main.id where main.id in (1,2,3);
returns:
+------+------------+
| id | text |
+------+------------+
| 1 | something1 |
+------+------------+
How to get
+------+------------+
| id | text |
+------+------------+
| 1 | something2 |
+------+------------+
Try the following SQL statement:
Edit:
In case you need several columns from table test, you need to add a primary key. Then, in your query, first obtain the primary key column and use it as reference on the following sub queries: