u/Spendocrat

select row with most-recent date for each ID

I have two tables, Table1 has a list of medication orders, and Table2 has a list of transactions related to the orders in Table1 (one-to-many relationship).

Is there a way to use a single SQL query to select only the most-recent transaction row from the transaction table for each row in the medication orders table?

Table2 has columns: transaction_id, order_id (foreign key to Table1), t_date, t_time, etc. to represent transactions related to the medication orders in Table1.

Hopefully that's clear. I can't wrap my head around using max() in this way.

reddit.com
u/Spendocrat — 5 days ago