Joining tables while using group by in SQL

I have two tables to join in SQL using the ID column in both. Table 1 has only unique values of ID as follows and I want to keep all columns of this table:

ID     code 1    code 2      
1       123       99
2       222       09
3       344       13

Table 2 has multiple rows of each ID as follows:

ID    application_time     
 1       11jan2004
 2       15oct2010
 1       24nov2008
 3       05sep2010
 1       07feb2001
 2       24aug2017
 3       12mar2009
 2       11dec2001

So, from table 2, I want to add the total count of each ID, and Min and Max of Application_time to table 1. I do not know where I should use group by (). So the outcome should look like:

ID     code 1    code 2  count   Min (application_time)   Max (application_time)  
1       123       99       3          07feb2001                    24nov2008
2       222       09       3          11dec2001                    24aug2017
3       344       13       2          12mar2009                    05sep2010


Read more here: https://stackoverflow.com/questions/65710751/joining-tables-while-using-group-by-in-sql

Content Attribution

This content was originally published by Alex at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: