Categories
Database Development

Select max date that corresponds with other tables

I have 2 tables. They look like this:

table a:

id   datetime             value
---- -------------------  -----
1    2020-05-20 07:34:46  1
2    2020-05-20 07:34:46  2
3    2020-05-20 07:34:46  3
4    2020-05-20 07:34:46  4
5    2020-05-20 07:34:46  5
6    2020-05-23 07:35:46  5

table b:

id   value2
---- ------
1    a
2    a
3    b
4    c
5    c

I would like to get back the data from table a and b with a.value and b.id, with the latest data and where value2 is c.

For example:

id   datetime             value value2
---- -------------------  ----- ------
4    2020-05-20 07:34:46  4     c
6    2020-05-23 07:35:46  6     c

Thanks so much 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *