1I have the following two tables (sample data) and need to be able to group the all the id‘s which belong to the larger group called code and dateCreated, group when the dates are the same for the code
table1:
dateCreated | id
2011-12-27 | 1
2011-12-15 | 2
2011-12-17 | 6
2011-12-26 | 15
2011-12-15 | 18
2011-12-07 | 22
2011-12-09 | 23
2011-12-27 | 24
table2:
code | id
EFG | 1
ABC | 2
BCD | 6
BCD | 15
ABC | 18
BCD | 22
EFG | 23
EFG | 24
So the results (Hopefully right) should I need would be where codes are grouped by date:
dateCreated | code
2011-12-27 | EFG
2011-12-15 | ABC
2011-12-17 | BCD
2011-12-26 | BCD
2011-12-07 | BCD
2011-12-09 | EFG
Hopefully this makes sense….
I’ve tried a few things most recent something like this but without any luck (invalid column GroupCodes)
select dateCreated, (SELECT distinct code
FROM table2 INNER JOIN
table1 ON id = table2.id) as GroupCodes
from table1
group by dateCreated, GroupCodes
Maybe I’m missing the issue, but wouldn’t the following work?