Skip to content
Advertisement

Min and max with conditions in single sql query

I have a table like

I want to get date of next appointment and previous appointment in single query.

I created query as

which works as expected, but I think it is not optimized because two subqueries. Can you help me to optimize me such query,please?

Advertisement

Answer

you can use case when expression

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