Jannic
Your sample data was so simple that I couldn't understand your requirement.
Because, I could make a query to get your sample result without seeing any table other than table1.
Here is an example
(This must not be your requered query!):
Code:
SELECT id AS "mainTable.id"
, start_date AS "table1.start_date"
FROM table1
;
My question is that all mainTableId in table1Child are in mainTable?
If answer is yes, then you need not to see mainTable.
So, I assumed that some mainTableId in table1Child may be not in mainTable.
For example:
mainTable:
1d
1
3
4
table1:
id start_date
10 '2009-01-02'
20 '2009-01-03'
table1Child:
table1Id mainTableId
10 1
10 2
10 3
10 4
10 5
20 2
20 3
Expected result:
mainTable.id, table1.start_date
4, 2009-01-02
3, 2009-01-03
Then, a query may be:
Code:
------------------------------ Commands Entered ------------------------------
SELECT (SELECT MAX(m.Id)
FROM table1Child AS t1c
JOIN mainTable AS m
ON m.id = t1c.mainTableId
WHERE t1c.table1Id = t1.id
) AS "mainTable.id"
, start_date AS "table1.start_date"
FROM table1 t1
;
------------------------------------------------------------------------------
mainTable.id table1.start_date
------------ -----------------
4 2009-01-02
3 2009-01-03
2 record(s) selected.
If the data or result was defferent from your requirement,
please give me enough sample data and expected result.