Skip to content
Advertisement

How to join max/min date column on select with last date where data on it

I have to join one table with 2 parameters to show last update status of detail to check finish/ongoing with MAX(…)/MIN(…). What can i do for this?

I have tried LEFT JOIN but it return to null

after I query I get this

I have expect this (stop is last b1 used in a1 , lastdate is last b1 used in all table)

UPDATE I finally get this but still concern about time to query performance because MAX(…) will fetch entire table right? How can I improve this performance.

Advertisement

Answer

I think that simple subquery would make the job faster, this way you eliminate double grouping, which is not neccesary:

dbfiddle demo

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement