I have two tables and I only want a start date from a query on table2 to be added to the values on table1. The start date is deduced with a GROUP BY statement, for example:
Table 1
| ID | Summary | End |
|---|---|---|
| 1 | Heading | 01/01/2023 |
| 2 | Heading 2 | 02/02/2023 |
Table 2
| ID | Summary | Start | Parent ID |
|---|---|---|---|
| 3 | Heading | 01/10/2022 | 1 |
| 4 | Heading 2 | 02/10/2023 | 1 |
| 5 | Heading 3 | 03/10/2023 | 2 |
I would like to have all of table 1 with just the minimum start date for each Parent ID from Table 2.
I tried something like this but I can't get the extra columns to return, I'm guessing I need to change something with the GROUP BY clause?
SELECT table1.*, t2.Start
FROM table1 INNER JOIN
(
SELECT [Parent ID], min(Start)
FROM table2
GROUP BY [Parent ID]
) t2 ON t2.[Parent ID] = t1.ID